discovery

package
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2022 License: MIT Imports: 4 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var EmptyOptions = func() *Options {
	return &Options{
		TTL: time.Second * 3,
	}
}

Functions

func ContextWithDiscovery

func ContextWithDiscovery(ctx context.Context) context.Context

func RegisterBackendImplementor added in v2.0.2

func RegisterBackendImplementor(backend Backend)

RegisterBackendImplementor registers the discovery backend service implementor.

func RegisterImplementor

func RegisterImplementor(svc Discovery)

RegisterImplementor registers the discovery service implementor.

func StreamServerInterceptor

func StreamServerInterceptor() grpc.StreamServerInterceptor

StreamServerInterceptor returns a new streaming server interceptor for service discovery.

func UnaryServerInterceptor

func UnaryServerInterceptor() grpc.UnaryServerInterceptor

UnaryServerInterceptor returns a new unary server interceptor for service discovery.

Types

type Backend added in v2.0.2

type Backend interface {
	// Type returns the backend provider type.
	Type() string

	// Set value for the specified key with a specified ttl.
	Set(key, value string, ttl time.Duration) error

	// Get the value of the specified key or directory.
	Get(key string, dir bool) (*KVPairs, error)

	// Incr invokes an atomic value increase for the specified key.
	Incr(key string) (int64, error)

	// Watch for changes of the specified key or directory.
	Watch(key string, version uint64, dir bool) (EventChan, error)

	// KeepAlive sets value and updates the ttl for the specified key.
	KeepAlive(key, value string, ttl time.Duration) error

	// Close the provider connection.
	Close()
}

Backend interface.

func BackendImplementor added in v2.0.2

func BackendImplementor() Backend

BackendImplementor returns the discovery backend service implementor.

type Discovery

type Discovery interface {
	// PassthroughAddr returns service unique ID and rpc address registered for the component.
	PassthroughAddr(component string) (int64, string)

	// Register rpc address of the component service address.
	Register(component, addr string, opts ...Option) (int64, error)

	// GetAddresses returns rpc service addresses.
	GetAddresses(service string) []resolver.Address
}

func ContextDiscovery

func ContextDiscovery(ctx context.Context) Discovery

func Implementor

func Implementor() Discovery

Implementor returns the discovery service implementor.

type EventChan added in v2.0.2

type EventChan chan *WatchEvent

type EventType added in v2.0.2

type EventType int
const (
	Update  EventType = iota + 1 // Key/value updated
	Delete                       // Key/value deleted
	Refresh                      // Refresh pah
)

type KVPair added in v2.0.2

type KVPair struct {
	Key     string
	Value   string
	Version uint64
}

type KVPairs added in v2.0.2

type KVPairs struct {
	KVs     []*KVPair
	Version uint64
}

type Option added in v2.0.2

type Option func(options *Options)

func WithIsolate added in v2.0.2

func WithIsolate(isolate bool) Option

func WithServices added in v2.0.2

func WithServices(services []string) Option

func WithTTL added in v2.0.2

func WithTTL(ttl time.Duration) Option

type Options added in v2.0.2

type Options struct {
	Isolate  bool
	TTL      time.Duration
	Services []string
}

type WatchEvent added in v2.0.2

type WatchEvent struct {
	EventType
	KVPair
}

Jump to

Keyboard shortcuts

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