Documentation ¶
Index ¶
- type Discovery
- type EtcdRegistry
- func (r *EtcdRegistry) GetService(ctx context.Context, name string) ([]*ServiceInstance, error)
- func (r *EtcdRegistry) Register(ctx context.Context, service *ServiceInstance) error
- func (r *EtcdRegistry) Unregister(ctx context.Context, service *ServiceInstance) error
- func (r *EtcdRegistry) Watch(ctx context.Context, name string) (Watcher, error)
- type GrpcServer
- type Option
- type Registrar
- type ServerOption
- type ServiceInstance
- type Watcher
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Discovery ¶
type Discovery interface { // GetService return the service instances in memory according to the service name. GetService(ctx context.Context, serviceName string) ([]*ServiceInstance, error) // Watch creates a watcher according to the service name. Watch(ctx context.Context, serviceName string) (Watcher, error) }
Discovery is service discovery.
type EtcdRegistry ¶
type EtcdRegistry struct {
// contains filtered or unexported fields
}
EtcdRegistry is etcd EtcdRegistry.
func NewEtcdRegistry ¶
func NewEtcdRegistry(client *clientv3.Client, opts ...Option) (r *EtcdRegistry)
NewEtcdRegistry creates etcd EtcdRegistry
func (*EtcdRegistry) GetService ¶
func (r *EtcdRegistry) GetService(ctx context.Context, name string) ([]*ServiceInstance, error)
GetService return the service instances in memory according to the service name.
func (*EtcdRegistry) Register ¶
func (r *EtcdRegistry) Register(ctx context.Context, service *ServiceInstance) error
Register the registration.
func (*EtcdRegistry) Unregister ¶
func (r *EtcdRegistry) Unregister(ctx context.Context, service *ServiceInstance) error
Unregister the registration.
type GrpcServer ¶
func NewGrpcServer ¶
func NewGrpcServer(name string, addr string, opts ...ServerOption) *GrpcServer
NewGrpcServer create grpc server
func (*GrpcServer) Start ¶
func (s *GrpcServer) Start() error
Start start grpc server with registrar option
type Option ¶
type Option func(o *options)
Option is etcd EtcdRegistry option.
func WithContext ¶
WithContext with EtcdRegistry context.
func WithNamespace ¶
WithNamespace with EtcdRegistry namespace.
func WithRegisterTTL ¶
WithRegisterTTL with register ttl.
type Registrar ¶
type Registrar interface { // Register the registration. Register(ctx context.Context, service *ServiceInstance) error // Unregister the registration. Unregister(ctx context.Context, service *ServiceInstance) error }
Registrar is service registrar.
type ServerOption ¶
type ServerOption func(server *GrpcServer)
func WithServerMetadata ¶
func WithServerMetadata(metadata map[string]string) ServerOption
func WithServerRegistrar ¶
func WithServerRegistrar(registrar Registrar) ServerOption
WithServerRegistrar set registrar
func WithServerTimeout ¶
func WithServerTimeout(timeout time.Duration) ServerOption
WithServerTimeout set timeout
type ServiceInstance ¶
type ServiceInstance struct { // Name is the service name as registered. Name string `json:"name"` Addr string `json:"address"` // Metadata is the kv pair metadata associated with the service instance. Metadata map[string]string `json:"metadata"` }
ServiceInstance is an instance of a service in a discovery system.
func (*ServiceInstance) String ¶
func (i *ServiceInstance) String() string
type Watcher ¶
type Watcher interface { // Next returns services in the following two cases: // 1.the first time to watch and the service instance list is not empty. // 2.any service instance changes found. // if the above two conditions are not met, it will block until context deadline exceeded or canceled Next() ([]*ServiceInstance, error) // Stop close the watcher. Stop() error }
Watcher is service watcher.