disco

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrWatcherClosed = errors.New("watcher closed")
)

Functions

func AgentWithContext

func AgentWithContext(ctx context.Context, agent Agent) context.Context

AgentWithContext returns a copy of parent in which the `Agent` is stored

Types

type Agent

type Agent interface {
	// Register adds a new service to the catalogue
	Register(ctx context.Context, s *Registration) (string, error)
	// Deregister removes a service from the catalogue
	// If the service does not exist, no action is taken.
	Deregister(ctx context.Context, id string) error
	// Services returns all registered service instances
	Services(ctx context.Context, tags ...string) (map[string]Service, error)
	// Service returns all instances of a service
	Service(ctx context.Context, name string, tags ...string) (Service, error)
	// Leave is used to have the agent de-register all services from the catalogue
	// that belong to this node, and gracefully leave
	Leave(ctx context.Context)
}

An Agent interacts with a service discovery cluster to manage all services offered by the local node. It also allows to query the service discovery cluster to fetch services offered by other nodes.

func AgentFromContext

func AgentFromContext(ctx contextutil.ValueContext) Agent

AgentFromContext returns an `Agent` instance associated with `ctx`, or the local `Agent` if no instance could be found.

func NewLocalAgent

func NewLocalAgent() Agent

NewLocalAgent returns a new local-only service discovery agent. This agent is used when service discovery is disabled.

type Diff

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

Diff stores a snapshot of instances and generate all events needed to go from one snapshot to the other. This simplifies the development of adapters that don't support incremental updates.

func (*Diff) Apply

func (d *Diff) Apply(state []*Instance) (events []*Event)

Apply returns all events needed to go from the current state to the new state

type Event

type Event struct {
	// Op indicates the operation of the update.
	Op Operation
	// Instance is the updated instance.
	Instance *Instance
}

Event defines an instance event

type Instance

type Instance struct {
	// Local tells whether it is a local or remote instance
	Local bool
	// ID is the unique instance identifier
	ID string
	// Name of the service
	Name string
	// Host is the IP address or DNS name
	Host string
	// Port defines the port on which the service runs
	Port uint16
	// Tags of that instance
	Tags []string
}

An Instance is an instance of a remotely-accessible service on the network

func (*Instance) Addr

func (i *Instance) Addr() string

Addr returns the instance host+port

type Operation

type Operation uint8

Operation defines the corresponding operations for a service update

const (
	// Add indicates a new instance is added.
	Add Operation = iota
	// Update indicates an existing instance is updated.
	Update
	// Delete indicates an exisiting instance is deleted.
	Delete
)

type Registration

type Registration struct {
	// ID is the unique identifier for the service (optional)
	ID string
	// Name is the service name
	Name string
	Addr string
	Port uint16
	Tags []string
}

Registration allows to register a service

type Service

type Service interface {
	// Name returns the unique name of a service
	Name() string
	// Watch listens to service updates
	Watch() Watcher
	// Instances returns all available instances of the service
	Instances() []*Instance
}

A Service is a set of functionalities offered by one or multiple nodes on the network. A node that offers the service is called an instance. A node can offer multiple services, so there will be multiple instances on the same node.

type Watcher

type Watcher interface {
	// Next blocks until an event or error happens. It may return one or more
	// events. The first call should get the full set of the results. It should
	// return an error if and only if Watcher cannot recover.
	Next() ([]*Event, error)
	// Close closes the Watcher.
	Close() error
}

Watcher watches for the updates on the specified service

Directories

Path Synopsis
consul
Package consul is a wrapper around the Hashicorp Consul service discovery functionnality
Package consul is a wrapper around the Hashicorp Consul service discovery functionnality

Jump to

Keyboard shortcuts

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