Documentation ¶
Overview ¶
Package gsvc provides service registry and discovery definition.
Index ¶
- Constants
- func Deregister(ctx context.Context, service *Service) error
- func Register(ctx context.Context, service *Service) error
- func SetRegistry(registry Registry)
- type Discovery
- type Metadata
- type Registrar
- type Registry
- type SearchInput
- type Service
- func Get(ctx context.Context, name string) (service *Service, err error)
- func GetWithWatch(ctx context.Context, name string, watch ServiceWatch) (service *Service, err error)
- func NewServiceWithKV(key, value []byte) (s *Service, err error)
- func NewServiceWithName(name string) (s *Service)
- func Search(ctx context.Context, in SearchInput) ([]*Service, error)
- type ServiceWatch
- type WatchInput
- type Watcher
Constants ¶
const ( Schema = `services` DefaultPrefix = `services` DefaultDeployment = `default` DefaultNamespace = `default` DefaultVersion = `latest` EnvPrefix = `GF_GSVC_PREFIX` EnvDeployment = `GF_GSVC_DEPLOYMENT` EnvNamespace = `GF_GSVC_NAMESPACE` EnvName = `GF_GSVC_Name` EnvVersion = `GF_GSVC_VERSION` MDProtocol = `protocol` MDInsecure = `insecure` MDWeight = `weight` )
Variables ¶
This section is empty.
Functions ¶
func Deregister ¶
Deregister removes `service` from default registry.
func SetRegistry ¶
func SetRegistry(registry Registry)
SetRegistry sets the default Registry implements as your own implemented interface.
Types ¶
type Discovery ¶
type Discovery interface { // Search searches and returns services with specified condition. Search(ctx context.Context, in SearchInput) ([]*Service, error) // Watch watches specified condition changes. Watch(ctx context.Context, key string) (Watcher, error) }
Discovery interface for service discovery.
type Metadata ¶
type Metadata map[string]interface{}
Metadata stores custom key-value pairs.
type Registrar ¶
type Registrar interface { // Register registers `service` to Registry. Register(ctx context.Context, service *Service) error // Deregister off-lines and removes `service` from Registry. Deregister(ctx context.Context, service *Service) error }
Registrar interface for service registrar.
type Registry ¶
Registry interface for service.
func GetRegistry ¶
func GetRegistry() Registry
GetRegistry returns the default Registry that is previously set. It returns nil if no Registry is set.
type SearchInput ¶
type SearchInput struct { Prefix string // Service prefix. Deployment string // Service deployment name, eg: dev, qa, staging, prod, etc. Namespace string // Service Namespace, to indicate different service in the same environment with the same Name. Name string // Name for the service. Version string // Service version, eg: v1.0.0, v2.1.1, etc.} }
SearchInput is the input for service searching.
func (*SearchInput) Key ¶
func (s *SearchInput) Key() string
Key formats and returns a string for prefix searching purpose.
type Service ¶
type Service struct { Prefix string // Service prefix. Deployment string // Service deployment name, eg: dev, qa, staging, prod, etc. Namespace string // Service Namespace, to indicate different service in the same environment with the same Name. Name string // Name for the service. Version string // Service version, eg: v1.0.0, v2.1.1, etc. Endpoints []string // Service Endpoints, pattern: IP:port, eg: 192.168.1.2:8000. Metadata Metadata // Custom data for this service, which can be set using JSON by environment or command-line. }
Service definition.
func GetWithWatch ¶
func NewServiceWithKV ¶
NewServiceWithKV creates and returns service from `key` and `value`.
func NewServiceWithName ¶
NewServiceWithName creates and returns service from `name`.
func Search ¶
func Search(ctx context.Context, in SearchInput) ([]*Service, error)
Search searches and returns services with specified condition.
func (*Service) Key ¶
Key formats the service information and returns the Service as registering key.
func (*Service) KeyWithSchema ¶
KeyWithSchema formats the service information and returns the Service as dialing target key.
func (*Service) KeyWithoutEndpoints ¶
KeyWithoutEndpoints formats the service information and returns a string as unique name of service.
type ServiceWatch ¶
type ServiceWatch func(service *Service)
type WatchInput ¶
type WatchInput struct { Prefix string // Service prefix. Deployment string // Service deployment name, eg: dev, qa, staging, prod, etc. Namespace string // Service Namespace, to indicate different service in the same environment with the same Name. Name string // Name for the service. Version string // Service version, eg: v1.0.0, v2.1.1, etc.} }
WatchInput is the input for service watching.