Documentation
¶
Overview ¶
Package registry is an interface for service discovery
Index ¶
- Variables
- func Deregister(s *Service) error
- func Register(s *Service, opts ...RegisterOption) error
- func String() string
- type Endpoint
- type Node
- type Option
- type Options
- type RegisterOption
- type RegisterOptions
- type Registry
- type Result
- type Service
- type Value
- type WatchOption
- type WatchOptions
- type Watcher
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // DefaultRegistry 默认注册中心 DefaultRegistry = newConsulRegistry() // ErrNotFound ErrNotFound ErrNotFound = errors.New("not found") )
Functions ¶
func Register ¶
func Register(s *Service, opts ...RegisterOption) error
Register a service node. Additionally supply options such as TTL.
Types ¶
type Endpoint ¶
type Endpoint struct {
Name string `json:"name"`
Request *Value `json:"request"`
Response *Value `json:"response"`
Metadata map[string]string `json:"metadata"`
}
Endpoint 服务节点信息
type Node ¶
type Node struct {
Id string `json:"id"` // moduleType@xxx-id-xxx
Address string `json:"address"`
Port int `json:"port"`
Metadata map[string]string `json:"metadata"`
}
Node 服务节点信息
type Options ¶
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
}
Options Options
type RegisterOptions ¶
type RegisterOptions struct {
TTL time.Duration
// Other options for implementations of the interface
// can be stored in a context
Context context.Context
}
RegisterOptions RegisterOptions
type Registry ¶
type Registry interface {
Init(...Option) error
Options() Options
Register(*Service, ...RegisterOption) error
Deregister(*Service) error
GetService(string) ([]*Service, error)
ListServices() ([]*Service, error)
Watch(...WatchOption) (Watcher, error)
String() string
GetKV(key string) ([]byte, error)
}
Registry The registry provides an interface for service discovery and an abstraction over varying implementations {consul, etcd, zookeeper, ...}
type Result ¶
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 map[string]string `json:"metadata"`
Endpoints []*Endpoint `json:"endpoints"`
Nodes []*Node `json:"nodes"`
}
Service Service
func GetService ¶
GetService Retrieve a service. A slice is returned since we separate Name/Version.
func ListServices ¶
ListServices List the services. Only returns service names
type Value ¶
type Value struct {
Name string `json:"name"`
Type string `json:"type"`
Values []*Value `json:"values"`
}
Value Value
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
}
WatchOptions WatchOptions
Source Files
¶
Click to show internal directories.
Click to hide internal directories.