registry

package
v0.0.0-...-1b17b00 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

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.

func (*EtcdRegistry) Watch

func (r *EtcdRegistry) Watch(ctx context.Context, name string) (Watcher, error)

Watch creates a watcher according to the service name.

type GrpcServer

type GrpcServer struct {
	*grpc.Server
	// contains filtered or unexported fields
}

func NewGrpcServer

func NewGrpcServer(name string, addr string, opts ...ServerOption) *GrpcServer

NewGrpcServer create grpc server

func (*GrpcServer) Close

func (s *GrpcServer) Close() error

Close close grpc server

func (*GrpcServer) Endpoint

func (s *GrpcServer) Endpoint() (*url.URL, error)

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

func WithContext(ctx context.Context) Option

WithContext with EtcdRegistry context.

func WithMaxRetry

func WithMaxRetry(num int) Option

WithMaxRetry with max retry.

func WithNamespace

func WithNamespace(ns string) Option

WithNamespace with EtcdRegistry namespace.

func WithRegisterTTL

func WithRegisterTTL(ttl time.Duration) Option

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 Endpoint

func Endpoint(endpoint *url.URL) ServerOption

Endpoint with server address.

func TLSConfig

func TLSConfig(c *tls.Config) ServerOption

TLSConfig with TLS config.

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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