membership

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2022 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package membership provides Go types for dealing with various data formats used to advertize a server's presence using services like ZooKeeper or Etcd.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TCPAddrFromServerSetEndpoint

func TCPAddrFromServerSetEndpoint(ep *ServerSetEndpoint) (*net.TCPAddr, error)

TCPAddrFromServerSetEndpoint is a helper function that parses an existing ServerSetEndpoint to produce a TCPAddr.

Types

type ConflictingAddressesError added in v0.4.7

type ConflictingAddressesError struct {
	A net.IP
	B net.IP
}

ConflictingAddressesError represents a conflicting attempt to use two different IP addresses to refer to the same server. The ServerSet format supports this, but Roxy format does not.

func (ConflictingAddressesError) Error added in v0.4.7

func (err ConflictingAddressesError) Error() string

Error fulfills the error interface.

type ConflictingZonesError added in v0.4.7

type ConflictingZonesError struct {
	A string
	B string
}

ConflictingZonesError represents a conflicting attempt to use two different IPv6 zones to refer to the same server. The ServerSet format supports this, but Roxy format does not.

func (ConflictingZonesError) Error added in v0.4.7

func (err ConflictingZonesError) Error() string

Error fulfills the error interface.

type GRPC

type GRPC struct {
	Op       GRPCOperation `json:"Op"`
	Addr     string        `json:"Addr"`
	Metadata interface{}   `json:"Metadata,omitempty"`
}

GRPC represents a service advertisement in etcd.io's gRPC Naming format.

See: https://etcd.io/docs/v3.4/dev-guide/grpc_naming/

func (*GRPC) IsAlive added in v0.4.4

func (grpc *GRPC) IsAlive() bool

IsAlive returns true if this represents the advertisement of a live server.

func (*GRPC) NamedAddr added in v0.4.4

func (grpc *GRPC) NamedAddr(namedPort string) *net.TCPAddr

NamedAddr returns the server's named endpoint as a TCPAddr.

(For GRPC format, this always panics for non-"" namedPort.)

func (*GRPC) NamedPorts added in v0.4.4

func (grpc *GRPC) NamedPorts() []string

NamedPorts returns the list of named ports advertized by the server.

(For GRPC format, this is always the nil list.)

func (*GRPC) PrimaryAddr added in v0.4.4

func (grpc *GRPC) PrimaryAddr() *net.TCPAddr

PrimaryAddr returns the server's primary endpoint as a TCPAddr.

type GRPCOperation

type GRPCOperation uint8

GRPCOperation represents the status of the server being advertized.

const (
	GRPCOpAdd GRPCOperation = iota
	GRPCOpDelete
)

GRPCOperation constants:

GRPCOpAdd     healthy
GRPCOpDelete  not healthy

func (GRPCOperation) GoString

func (op GRPCOperation) GoString() string

GoString fulfills fmt.GoStringer.

func (GRPCOperation) MarshalJSON

func (op GRPCOperation) MarshalJSON() ([]byte, error)

MarshalJSON fulfills json.Marshaler.

func (GRPCOperation) String

func (op GRPCOperation) String() string

String fulfills fmt.Stringer.

func (*GRPCOperation) UnmarshalJSON

func (op *GRPCOperation) UnmarshalJSON(raw []byte) error

UnmarshalJSON fulfills json.Unmarshaler.

type Interface added in v0.4.4

type Interface interface {
	IsAlive() bool
	NamedPorts() []string
	PrimaryAddr() *net.TCPAddr
	NamedAddr(string) *net.TCPAddr
}

Interface is the minimum interface supported by all advertisement formats.

type Roxy

type Roxy struct {
	Ready           bool
	IP              net.IP
	Zone            string
	ServerName      string
	PrimaryPort     uint16
	AdditionalPorts map[string]uint16
	ShardNumber     uint32
	HasShardNumber  bool
	Metadata        map[string]string
}

Roxy represents a service advertisement in Roxy's native format.

See RoxyJSON for details about the JSON serialization format.

func (*Roxy) AsGRPC

func (r *Roxy) AsGRPC(namedPort string) *GRPC

AsGRPC returns the GRPC representation of this server advertisement.

func (*Roxy) AsRoxyJSON

func (r *Roxy) AsRoxyJSON() *RoxyJSON

AsRoxyJSON returns the RoxyJSON representation of this server advertisement.

func (*Roxy) AsServerSet

func (r *Roxy) AsServerSet() *ServerSet

AsServerSet returns the ServerSet representation of this server advertisement.

func (*Roxy) FromGRPC

func (r *Roxy) FromGRPC(grpc *GRPC) error

FromGRPC initializes this server advertisement to be a copy of a GRPC.

func (*Roxy) FromRoxyJSON

func (r *Roxy) FromRoxyJSON(x *RoxyJSON) error

FromRoxyJSON initializes this server advertisement to be a copy of a RoxyJSON.

func (*Roxy) FromServerSet

func (r *Roxy) FromServerSet(ss *ServerSet) error

FromServerSet initializes this server advertisement to be a copy of a ServerSet.

func (*Roxy) IsAlive added in v0.4.4

func (r *Roxy) IsAlive() bool

IsAlive returns true if this represents the advertisement of a live server.

func (*Roxy) MarshalJSON

func (r *Roxy) MarshalJSON() ([]byte, error)

MarshalJSON fulfills json.Marshaler.

func (*Roxy) NamedAddr

func (r *Roxy) NamedAddr(namedPort string) *net.TCPAddr

NamedAddr returns the server's named endpoint as a TCPAddr.

func (*Roxy) NamedPorts

func (r *Roxy) NamedPorts() []string

NamedPorts returns the list of named ports advertized by the server.

func (*Roxy) PrimaryAddr

func (r *Roxy) PrimaryAddr() *net.TCPAddr

PrimaryAddr returns the server's primary endpoint as a TCPAddr.

func (*Roxy) UnmarshalJSON

func (r *Roxy) UnmarshalJSON(raw []byte) error

UnmarshalJSON fulfills json.Unmarshaler.

type RoxyJSON

type RoxyJSON struct {
	Ready           bool              `json:"ready"`
	IP              string            `json:"ip,omitempty"`
	Zone            string            `json:"zone,omitempty"`
	ServerName      string            `json:"serverName,omitempty"`
	PrimaryPort     uint16            `json:"primaryPort,omitempty"`
	AdditionalPorts map[string]uint16 `json:"additionalPorts,omitempty"`
	ShardNumber     *uint32           `json:"shard,omitempty"`
	Metadata        map[string]string `json:"metadata,omitempty"`
}

RoxyJSON is a variant of Roxy, ready for JSON serialization.

Compared to Roxy, RoxyJSON serializes IP addresses in the usual string format, rather than representing them as net.IP byte arrays.

type ServerSet

type ServerSet struct {
	ServiceEndpoint     *ServerSetEndpoint            `json:"serviceEndpoint"`
	AdditionalEndpoints map[string]*ServerSetEndpoint `json:"additionalEndpoints"`
	Status              ServerSetStatus               `json:"status"`
	ShardNumber         *int32                        `json:"shard,omitempty"`
	Metadata            map[string]string             `json:"metadata,omitempty"`
}

ServerSet represents a service advertisement in Finagle's ServerSet format.

See: https://github.com/twitter/finagle/blob/develop/finagle-serversets/src/main/scala/com/twitter/finagle/serverset2/Entry.scala

func (*ServerSet) IsAlive

func (ss *ServerSet) IsAlive() bool

IsAlive returns true if this represents the advertisement of a live server.

func (*ServerSet) NamedAddr added in v0.4.4

func (ss *ServerSet) NamedAddr(namedPort string) *net.TCPAddr

NamedAddr returns the server's named endpoint as a TCPAddr.

func (*ServerSet) NamedPorts added in v0.4.4

func (ss *ServerSet) NamedPorts() []string

NamedPorts returns the list of named ports advertized by the server.

func (*ServerSet) PrimaryAddr added in v0.4.4

func (ss *ServerSet) PrimaryAddr() *net.TCPAddr

PrimaryAddr returns the server's primary endpoint as a TCPAddr.

type ServerSetEndpoint

type ServerSetEndpoint struct {
	Host string `json:"host"`
	Port uint16 `json:"port"`
}

ServerSetEndpoint represents a single endpoint in a ServerSet advertisement.

Each server's ServerSet can contain one primary and multiple named endpoints.

func ServerSetEndpointFromTCPAddr

func ServerSetEndpointFromTCPAddr(addr *net.TCPAddr) *ServerSetEndpoint

ServerSetEndpointFromTCPAddr is a helper function that creates a new ServerSetEndpoint representing the given TCPAddr.

func (*ServerSetEndpoint) Addr added in v0.4.4

func (ep *ServerSetEndpoint) Addr() *net.TCPAddr

Addr returns this endpoint as a TCPAddr. Panics if the endpoint data cannot be parsed as an IP and port.

type ServerSetStatus

type ServerSetStatus uint8

ServerSetStatus represents the status of the server being advertized.

const (
	StatusDead ServerSetStatus = iota
	StatusStarting
	StatusAlive
	StatusStopping
	StatusStopped
	StatusWarning
)

ServerSetStatus constants:

StatusAlive    healthy
anything else  not healthy

func (ServerSetStatus) GoString

func (status ServerSetStatus) GoString() string

GoString fulfills fmt.GoStringer.

func (ServerSetStatus) MarshalJSON

func (status ServerSetStatus) MarshalJSON() ([]byte, error)

MarshalJSON fulfills json.Marshaler.

func (ServerSetStatus) String

func (status ServerSetStatus) String() string

String fulfills fmt.Stringer.

func (*ServerSetStatus) UnmarshalJSON

func (status *ServerSetStatus) UnmarshalJSON(raw []byte) error

UnmarshalJSON fulfills json.Unmarshaler.

Jump to

Keyboard shortcuts

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