register

package
v3.7.8 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package register is an interface for service discovery

Index

Constants

View Source
const (
	// WildcardDomain indicates any domain
	WildcardDomain = "*"
	// DefaultDomain to use if none was provided in options
	DefaultDomain = "micro"
)

Variables

View Source
var (
	// DefaultRegister is the global default register
	DefaultRegister Register = NewRegister()
	// ErrNotFound returned when LookupService is called and no services found
	ErrNotFound = errors.New("service not found")
	// ErrWatcherStopped returned when when watcher is stopped
	ErrWatcherStopped = errors.New("watcher stopped")
)

Functions

func ExtractSubValue

func ExtractSubValue(typ reflect.Type) string

ExtractSubValue exctact *Value from reflect.Type

func ExtractValue

func ExtractValue(v reflect.Type, d int) string

ExtractValue from reflect.Type from specified depth

func NewContext

func NewContext(ctx context.Context, c Register) context.Context

NewContext put register in context

Types

type DeregisterOption

type DeregisterOption func(*DeregisterOptions)

DeregisterOption option is used to deregister service

func DeregisterAttempts added in v3.2.12

func DeregisterAttempts(t int) DeregisterOption

DeregisterAttempts specifies deregister atempts count

func DeregisterContext

func DeregisterContext(ctx context.Context) DeregisterOption

DeregisterContext sets the context for deregister method

func DeregisterDomain

func DeregisterDomain(d string) DeregisterOption

DeregisterDomain specifies deregister domain

type DeregisterOptions

type DeregisterOptions struct {
	Context context.Context
	// Domain the service was registered in
	Domain string
	// Atempts specify max attempts for deregister
	Attempts int
}

DeregisterOptions holds options for deregister method

func NewDeregisterOptions

func NewDeregisterOptions(opts ...DeregisterOption) DeregisterOptions

NewDeregisterOptions returns options for deregister filled by opts

type Endpoint

type Endpoint struct {
	Request  string            `json:"request"`
	Response string            `json:"response"`
	Metadata metadata.Metadata `json:"metadata"`
	Name     string            `json:"name"`
}

Endpoint holds endpoint register info

func ExtractEndpoint

func ExtractEndpoint(method reflect.Method) *Endpoint

ExtractEndpoint extract *Endpoint from reflect.Method

type Event

type Event struct {
	// Timestamp is event timestamp
	Timestamp time.Time
	// Service is register service
	Service *Service
	// ID is register id
	ID string
	// Type defines type of event
	Type EventType
}

Event is register event

type EventType

type EventType int

EventType defines register event type

const (
	// Create is emitted when a new service is registered
	Create EventType = iota
	// Delete is emitted when an existing service is deregistered
	Delete
	// Update is emitted when an existing service is updated
	Update
)

func (EventType) String

func (t EventType) String() string

String returns human readable event type

type ListOption

type ListOption func(*ListOptions)

ListOption option is used to list services

func ListContext

func ListContext(ctx context.Context) ListOption

ListContext specifies context for list method

func ListDomain

func ListDomain(d string) ListOption

ListDomain sets the domain for list method

type ListOptions

type ListOptions struct {
	Context context.Context
	// Domain to scope the request to
	Domain string
}

ListOptions holds the list options for list method

func NewListOptions

func NewListOptions(opts ...ListOption) ListOptions

NewListOptions returns list options filled by opts

type LookupOption

type LookupOption func(*LookupOptions)

LookupOption option is used to get service

func LookupContext added in v3.2.2

func LookupContext(ctx context.Context) LookupOption

LookupContext sets the context for lookup method

func LookupDomain added in v3.2.2

func LookupDomain(d string) LookupOption

LookupDomain sets the domain for lookup

type LookupOptions

type LookupOptions struct {
	Context context.Context
	// Domain to scope the request to
	Domain string
}

LookupOptions holds lookup options

func NewLookupOptions

func NewLookupOptions(opts ...LookupOption) LookupOptions

NewLookupOptions returns lookup options filled by opts

type Node

type Node struct {
	Metadata metadata.Metadata `json:"metadata"`
	ID       string            `json:"id"`
	Address  string            `json:"address"`
}

Node holds node register info

type Option

type Option func(*Options)

Option func signature

func Addrs

func Addrs(addrs ...string) Option

Addrs is the register addresses to use

func Context

func Context(ctx context.Context) Option

Context sets the context

func Logger

func Logger(l logger.Logger) Option

Logger sets the logger

func Meter

func Meter(m meter.Meter) Option

Meter sets the meter

func Name added in v3.2.1

func Name(n string) Option

Name sets the name

func SetOption

func SetOption(k, v interface{}) Option

SetOption returns a function to setup a context with given value

func TLSConfig

func TLSConfig(t *tls.Config) Option

TLSConfig Specify TLS Config

func Timeout

func Timeout(t time.Duration) Option

Timeout sets the timeout

func Tracer

func Tracer(t tracer.Tracer) Option

Tracer sets the tracer

type Options

type Options struct {
	// Tracer used for tracing
	Tracer tracer.Tracer
	// Context holds external options
	Context context.Context
	// Logged used for logging
	Logger logger.Logger
	// Meter used for metrics
	Meter meter.Meter
	// TLSConfig holds tls.TLSConfig options
	TLSConfig *tls.Config
	// Name holds the name of register
	Name string
	// Addrs specifies register addrs
	Addrs []string
	// Timeout specifies timeout
	Timeout time.Duration
}

Options holds options for register

func NewOptions

func NewOptions(opts ...Option) Options

NewOptions returns options that filled by opts

type Register

type Register interface {
	Name() string
	Init(...Option) error
	Options() Options
	Connect(context.Context) error
	Disconnect(context.Context) error
	Register(context.Context, *Service, ...RegisterOption) error
	Deregister(context.Context, *Service, ...DeregisterOption) error
	LookupService(context.Context, string, ...LookupOption) ([]*Service, error)
	ListServices(context.Context, ...ListOption) ([]*Service, error)
	Watch(context.Context, ...WatchOption) (Watcher, error)
	String() string
}

Register provides an interface for service discovery and an abstraction over varying implementations {consul, etcd, zookeeper, ...}

func FromContext

func FromContext(ctx context.Context) (Register, bool)

FromContext get register from context

func NewRegister

func NewRegister(opts ...Option) Register

NewRegister returns an initialized in-memory register

type RegisterOption

type RegisterOption func(*RegisterOptions)

nolint: golint,revive RegisterOption option is used to register service

func RegisterAttempts

func RegisterAttempts(t int) RegisterOption

nolint: golint,revive RegisterAttempts specifies register atempts count

func RegisterContext

func RegisterContext(ctx context.Context) RegisterOption

nolint: golint,revive RegisterContext sets the register context

func RegisterDomain

func RegisterDomain(d string) RegisterOption

nolint: golint,revive RegisterDomain secifies register domain

func RegisterTTL

func RegisterTTL(t time.Duration) RegisterOption

nolint: golint,revive RegisterTTL specifies register ttl

type RegisterOptions

type RegisterOptions struct {
	Context  context.Context
	Domain   string
	TTL      time.Duration
	Attempts int
}

nolint: golint,revive RegisterOptions holds options for register method

func NewRegisterOptions

func NewRegisterOptions(opts ...RegisterOption) RegisterOptions

NewRegisterOptions returns register options struct filled by opts

type Result

type Result struct {
	// Service holds register service
	Service *Service
	// Action holds the action
	Action string
}

Result is returned by a call to Next on the watcher. Actions can be create, update, delete

type Service

type Service struct {
	Name      string            `json:"name"`
	Version   string            `json:"version"`
	Metadata  metadata.Metadata `json:"metadata"`
	Endpoints []*Endpoint       `json:"endpoints"`
	Nodes     []*Node           `json:"nodes"`
}

Service holds service register info

type WatchOption

type WatchOption func(*WatchOptions)

WatchOption option is used to watch service changes

func WatchContext

func WatchContext(ctx context.Context) WatchOption

WatchContext sets the context for watch method

func WatchDomain

func WatchDomain(d string) WatchOption

WatchDomain sets the domain for watch

func WatchService

func WatchService(name string) WatchOption

WatchService name

type WatchOptions

type WatchOptions struct {
	// Specify a service to watch
	// If blank, the watch is for all services
	Service string
	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
	// Domain to watch
	Domain string
}

WatchOptions holds watch options

func NewWatchOptions

func NewWatchOptions(opts ...WatchOption) WatchOptions

NewWatchOptions returns watch options filled by opts

type Watcher

type Watcher interface {
	// Next is a blocking call
	Next() (*Result, error)
	// Stop stops the watcher
	Stop()
}

Watcher is an interface that returns updates about services within the register.

Jump to

Keyboard shortcuts

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