discovery

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2022 License: MIT Imports: 5 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrExist = errors.New("discovery: id exist")

ErrExist represents an error in case of id already existed.

Functions

func IsExist added in v0.0.18

func IsExist(err error) bool

IsExist reports whether the err is ErrExist

func Register

func Register(driverName string, driver Driver)

Register makes a discovery driver available by the provided name

Types

type Discovery

type Discovery interface {
	// Register registers a service, if nx is true, the id must not exist.
	// Otherwise, ErrExist returned. If ttl > 0, the service has a expires time.
	Register(ctx context.Context, name, id, content string, nx bool, ttl time.Duration) error
	// Unregister unregisters a service
	Unregister(ctx context.Context, name, id string) error
	// Find finds service by name and id
	Find(ctx context.Context, name, id string) (content string, err error)
	// Resolve resolves any one service by name
	Resolve(ctx context.Context, name string) (id, content string, err error)
	// Resolve resolves all services by name
	ResolveAll(ctx context.Context, name string) (map[string]string, error)
}

Discovery represents a interface for service discovery

func Open

func Open(driverName, source string) (Discovery, error)

Open opens a discovery specified by its discovery driver name and a driver-specific source.

type Driver

type Driver interface {
	// Open returns a new discovery instance by a driver-specific source name
	Open(source string) (Discovery, error)
}

Driver is the interface that must be implemented by a discovery driver

Jump to

Keyboard shortcuts

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