go-micro: github.com/micro/go-micro/registry Index | Files | Directories

package registry

import "github.com/micro/go-micro/registry"

Package registry is an interface for service discovery


Package Files

mdns_registry.go options.go registry.go watcher.go


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


var (
    DefaultRegistry = NewRegistry()

    // Not found error when GetService is called
    ErrNotFound = errors.New("service not found")
    // Watcher stopped error when watcher is stopped
    ErrWatcherStopped = errors.New("watcher stopped")

func Deregister Uses

func Deregister(s *Service) error

Deregister a service node

func Register Uses

func Register(s *Service, opts ...RegisterOption) error

Register a service node. Additionally supply options such as TTL.

func String Uses

func String() string

type DeregisterOption Uses

type DeregisterOption func(*DeregisterOptions)

func DeregisterContext Uses

func DeregisterContext(ctx context.Context) DeregisterOption

func DeregisterDomain Uses

func DeregisterDomain(d string) DeregisterOption

type DeregisterOptions Uses

type DeregisterOptions struct {
    Context context.Context
    // Domain the service was registered in
    Domain string

type Endpoint Uses

type Endpoint struct {
    Name     string            `json:"name"`
    Request  *Value            `json:"request"`
    Response *Value            `json:"response"`
    Metadata map[string]string `json:"metadata"`

type Event Uses

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

Event is registry event

type EventType Uses

type EventType int

EventType defines registry event type

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

func (EventType) String Uses

func (t EventType) String() string

String returns human readable event type

type GetOption Uses

type GetOption func(*GetOptions)

func GetContext Uses

func GetContext(ctx context.Context) GetOption

func GetDomain Uses

func GetDomain(d string) GetOption

type GetOptions Uses

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

type ListOption Uses

type ListOption func(*ListOptions)

func ListContext Uses

func ListContext(ctx context.Context) ListOption

func ListDomain Uses

func ListDomain(d string) ListOption

type ListOptions Uses

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

type Node Uses

type Node struct {
    Id       string            `json:"id"`
    Address  string            `json:"address"`
    Metadata map[string]string `json:"metadata"`

type Option Uses

type Option func(*Options)

func Addrs Uses

func Addrs(addrs ...string) Option

Addrs is the registry addresses to use

func Secure Uses

func Secure(b bool) Option

Secure communication with the registry

func TLSConfig Uses

func TLSConfig(t *tls.Config) Option

Specify TLS Config

func Timeout Uses

func Timeout(t time.Duration) Option

type Options Uses

type Options struct {
    Addrs     []string
    Timeout   time.Duration
    Secure    bool
    TLSConfig *tls.Config
    // Other options for implementations of the interface
    // can be stored in a context
    Context context.Context

type RegisterOption Uses

type RegisterOption func(*RegisterOptions)

func RegisterContext Uses

func RegisterContext(ctx context.Context) RegisterOption

func RegisterDomain Uses

func RegisterDomain(d string) RegisterOption

func RegisterTTL Uses

func RegisterTTL(t time.Duration) RegisterOption

type RegisterOptions Uses

type RegisterOptions struct {
    TTL time.Duration
    // Other options for implementations of the interface
    // can be stored in a context
    Context context.Context
    // Domain to register the service in
    Domain string

type Registry Uses

type Registry interface {
    Init(...Option) error
    Options() Options
    Register(*Service, ...RegisterOption) error
    Deregister(*Service, ...DeregisterOption) error
    GetService(string, ...GetOption) ([]*Service, error)
    ListServices(...ListOption) ([]*Service, error)
    Watch(...WatchOption) (Watcher, error)
    String() string

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

func NewRegistry Uses

func NewRegistry(opts ...Option) Registry

NewRegistry returns a new default registry which is mdns

type Result Uses

type Result struct {
    Action  string
    Service *Service

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

type Service Uses

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

func GetService Uses

func GetService(name string) ([]*Service, error)

Retrieve a service. A slice is returned since we separate Name/Version.

func ListServices Uses

func ListServices() ([]*Service, error)

List the services. Only returns service names

type Value Uses

type Value struct {
    Name   string   `json:"name"`
    Type   string   `json:"type"`
    Values []*Value `json:"values"`

type WatchOption Uses

type WatchOption func(*WatchOptions)

func WatchContext Uses

func WatchContext(ctx context.Context) WatchOption

func WatchDomain Uses

func WatchDomain(d string) WatchOption

func WatchService Uses

func WatchService(name string) WatchOption

Watch a service

type WatchOptions Uses

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

type Watcher Uses

type Watcher interface {
    // Next is a blocking call
    Next() (*Result, error)

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

func Watch Uses

func Watch(opts ...WatchOption) (Watcher, error)

Watch returns a watcher which allows you to track updates to the registry.


cachePackage cache provides a registry cache
etcdPackage etcd provides an etcd service registry
mdnsPackage mdns provides a multicast dns registry
memoryPackage memory provides an in-memory registry
servicePackage service uses the registry service

Package registry imports 17 packages (graph) and is imported by 773 packages. Updated 2020-07-10. Refresh now. Tools for package owners.