host

package
v1.0.0-rc1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 15, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsEqual

func IsEqual(h1, h2 *Host) bool

IsEqual returns whether two hosts are the same.

Types

type Host

type Host struct {
	Addr string
	Type Type
	*Stats
	// contains filtered or unexported fields
}

Host represents a backend host.

func New

func New(addr string) *Host

New creates a host instance.

func NewWithType

func NewWithType(addr string, typ Type) *Host

NewWithType creates a host instance with specified type.

func (*Host) IsHealthy

func (h *Host) IsHealthy() bool

IsHealthy returns whether the host is healthy.

func (*Host) IsValid

func (h *Host) IsValid() bool

IsValid returns true if host is valid.

func (*Host) MarshalJSON

func (h *Host) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*Host) String

func (h *Host) String() string

String returns the string representation of Host.

func (*Host) UnmarshalJSON

func (h *Host) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

func (*Host) Validate

func (h *Host) Validate() error

Validate validates inner address and type and returns the first error.

func (*Host) WaitRemoved

func (h *Host) WaitRemoved() <-chan struct{}

WaitRemoved close when this host removed.

type Set

type Set struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Set is a hosts container.

func NewSet

func NewSet(hosts ...*Host) *Set

NewSet creates a set.

func (*Set) Add

func (set *Set) Add(hosts ...*Host)

Add adds host to the set.

func (*Set) All

func (set *Set) All() []*Host

All returns the all hosts.

func (*Set) Exist

func (set *Set) Exist(addr string) bool

func (*Set) Healthy

func (set *Set) Healthy() (hosts []*Host)

Healthy returns the healthy hosts.

func (*Set) Len

func (set *Set) Len() int

func (*Set) MarkHostHealthy

func (set *Set) MarkHostHealthy(host *Host) bool

MarkHostHealthy marks the given host as healthy.

func (*Set) MarkHostUnhealthy

func (set *Set) MarkHostUnhealthy(host *Host) bool

MarkHostUnhealthy marks the given host as unhealthy.

func (*Set) Random

func (set *Set) Random() *Host

func (*Set) Remove

func (set *Set) Remove(hosts ...*Host)

Remove removes host from the set.

func (*Set) ReplaceAll

func (set *Set) ReplaceAll(hosts []*Host)

ReplaceAll replaces the internal hosts atomicly.

type Stats

type Stats struct {
	// contains filtered or unexported fields
}

Stats describes the stats of a host.

func NewStats

func NewStats() *Stats

NewStats creates a stats container for host.

func (*Stats) ConnBytesInCounter

func (stats *Stats) ConnBytesInCounter() *atomic.Uint64

ConnBytesInCounter return input bytes counter.

func (*Stats) ConnBytesOutCounter

func (stats *Stats) ConnBytesOutCounter() *atomic.Uint64

ConnBytesOutCounter return output bytes counter.

func (*Stats) ConnCount

func (stats *Stats) ConnCount() uint64

ConnCount returns the connection count.

func (*Stats) DecConnCount

func (stats *Stats) DecConnCount()

DecConnCount decreases the connection count by 1.

func (*Stats) IncConnCount

func (stats *Stats) IncConnCount()

IncConnCount increases the connection count by 1.

func (*Stats) IncFailedCount

func (stats *Stats) IncFailedCount() uint64

IncFailedCount increase failed count by 1 and clears successful count.

func (*Stats) IncSuccessfulCount

func (stats *Stats) IncSuccessfulCount() uint64

IncSuccessfulCount increase successful count by 1 and clears failed count.

func (*Stats) MarshalJSON

func (stats *Stats) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

type Type

type Type int

Type indicates the type of host.

const (
	TypeMain Type = iota
	TypeBackup
)

Available host types.

func ParseType

func ParseType(typ string) Type

ParseType always returns a valid Type. If given "backup", it returns TypeBackup. Otherwise it returns TypeMain.

func (Type) MarshalJSON

func (typ Type) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler interface.

func (Type) String

func (typ Type) String() string

String returns the string representation of the host's type.

func (*Type) UnmarshalJSON

func (typ *Type) UnmarshalJSON(data []byte) error

UnmarshalJSON implements json.Unmarshaler interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL