Documentation
¶
Overview ¶
包gsvc提供了服务注册和发现的定义。 md5:d3c854663f57d96a
包gsvc提供了服务注册和发现的定义。 md5:d3c854663f57d96a
包gsvc提供了服务注册和发现的定义。 md5:d3c854663f57d96a
Index ¶
- Constants
- func Deregister(ctx context.Context, service Service) error
- func SetRegistry(registry Registry)
- type Discovery
- type Endpoint
- type Endpoints
- type LocalEndpoint
- type LocalService
- type Metadata
- type Registrar
- type Registry
- type SearchInput
- type Service
- func Get(ctx context.Context, name string) (service Service, err error)
- func GetAndWatch(ctx context.Context, name string, watch ServiceWatch) (service Service, err error)
- func GetAndWatchWithDiscovery(ctx context.Context, discovery Discovery, name string, watch ServiceWatch) (service Service, err error)
- func GetWithDiscovery(ctx context.Context, discovery Discovery, name string) (service Service, err error)
- func NewServiceWithKV(key, value string) (Service, error)
- func NewServiceWithName(name string) Service
- func Register(ctx context.Context, service Service) (Service, error)
- func Search(ctx context.Context, in SearchInput) ([]Service, error)
- type ServiceWatch
- type Watcher
Constants ¶
const ( Schema = `service` // Schema 是服务的架构。 md5:6a1b7f8839c75ab9 DefaultHead = `service` // DefaultHead 是服务的默认头部。 md5:d7d162114616b5b2 DefaultDeployment = `default` // DefaultDeployment 是服务的默认部署。 md5:65707ae0cef5a070 DefaultNamespace = `default` // DefaultNamespace 是服务的默认命名空间。 md5:4f63daab89c93e9b DefaultVersion = `latest` // DefaultVersion 是服务的默认版本。 md5:d4b3ea889260c002 EnvPrefix = `GF_GSVC_PREFIX` // EnvPrefix 是环境变量的前缀。 md5:f9c76700eaf507b7 EnvDeployment = `GF_GSVC_DEPLOYMENT` // EnvDeployment 是环境变量部署。 md5:debd2d8465c7fe29 EnvNamespace = `GF_GSVC_NAMESPACE` // EnvNamespace 是环境变量的命名空间。 md5:fc532cfcc9e08d5d EnvName = `GF_GSVC_Name` // EnvName 是环境变量的名称。 md5:40377ca0a4d5ab27 EnvVersion = `GF_GSVC_VERSION` // EnvVersion 是环境变量的版本。 md5:c2bc20cec15238b8 MDProtocol = `protocol` // MDProtocol是协议的元数据键。 md5:1263117efae5845d MDInsecure = `insecure` // MDInsecure是关于不安全的元数据键。 md5:f869d79b8547b1a2 MDWeight = `weight` // MDWeight 是用于权重的元数据键。 md5:48954b59a72a74ce DefaultProtocol = `http` // DefaultProtocol 是服务的默认协议。 md5:49c5538b8f79edc9 DefaultSeparator = "/" // DefaultSeparator是服务的默认分隔符。 md5:c24fd1db9709d190 EndpointHostPortDelimiter = ":" // EndpointHostPortDelimiter是主机和端口之间的分隔符。 md5:305b988da4318717 EndpointsDelimiter = "," // EndpointsDelimiter 是端点的分隔符。 md5:53e996ee7d6bcd61 )
Variables ¶
This section is empty.
Functions ¶
func Deregister ¶
Deregister 将 `service` 从默认注册表中移除。 md5:21de7624550ef4ed
func SetRegistry ¶
func SetRegistry(registry Registry)
SetRegistry 设置默认的Registry实现为你自定义实现的接口。 md5:4b1340106280e0dd
Types ¶
type Discovery ¶
type Discovery interface { // Search 搜索并返回符合指定条件的服务。 md5:62e529e326dae7b7 Search(ctx context.Context, in SearchInput) (result []Service, err error) // Watch 监视指定条件的变化。 // `key` 是服务键的前缀。 // md5:5f440541abba5ceb Watch(ctx context.Context, key string) (watcher Watcher, err error) }
服务发现的接口。 md5:c536eba406d0d0be
type Endpoint ¶
type Endpoint interface { // Host 返回服务的 IPv4/IPv6 地址。 md5:c70938f835a0f6e4 Host() string // Port 返回服务的端口。 md5:1650bc955f20ce4c Port() int // String 将Endpoint格式化并作为字符串返回。 md5:03761a672c1719e3 String() string }
服务的端点接口。 md5:949bbba900f0fdec
func NewEndpoint ¶
NewEndpoint 从地址字符串(格式为"host:port",如:"192.168.1.100:80")创建并返回一个Endpoint。 md5:837de544fe4ec26d
type Endpoints ¶
type Endpoints []Endpoint
终点(Endpoints)由多个Endpoint组成。 md5:253a91bd2341b2c5
func NewEndpoints ¶
NewEndpoints 从多个地址创建并返回 Endpoints,例如: "192.168.1.100:80,192.168.1.101:80"。 md5:a9ff1a4a1317ab38
type LocalEndpoint ¶
type LocalEndpoint struct {
// contains filtered or unexported fields
}
LocalEndpoint 实现了接口 Endpoint。 md5:2c8da8dce28b09e7
func (*LocalEndpoint) Host ¶
func (e *LocalEndpoint) Host() string
Host 返回服务的 IPv4/IPv6 地址。 md5:c70938f835a0f6e4
func (*LocalEndpoint) String ¶
func (e *LocalEndpoint) String() string
String 方法将Endpoint格式化为字符串,例如:192.168.1.100:80。 md5:b9ebe410fee82ac0
type LocalService ¶
type LocalService struct { Head string // 服务键中的自定义头部字符串。 md5:c33fc15669872592 Deployment string // 服务部署名称,例如:开发、测试、预发布、生产等。 md5:f4fb3f36ce08f902 Namespace string // 服务命名空间,用于在相同环境中标识具有相同名称的不同服务。 md5:9ef35b3338765912 Name string // Name for the service. Version string // 服务版本,例如:v1.0.0,v2.1.1 等等。 md5:ba8bedccf2112f4a Endpoints Endpoints // 服务端点,格式:IP:port,例如:192.168.1.2:8000。 md5:8898f7c8bc80d33e Metadata Metadata // 此服务的自定义数据,可以通过环境或命令行使用JSON进行设置。 md5:9eb9ae52ba435daf }
LocalService 提供了接口 Service 的默认实现。 md5:dd822c79690b7ca2
func (*LocalService) GetEndpoints ¶
func (s *LocalService) GetEndpoints() Endpoints
GetEndpoints 返回服务的端点信息。 端点包含服务的多个主机/端口信息。 md5:164bdc2d3a7db5e0
func (*LocalService) GetKey ¶
func (s *LocalService) GetKey() string
GetKey 格式化并返回服务的唯一键字符串。 生成的结果键通常用于键值注册服务器。 md5:8651d9bc2f308934
func (*LocalService) GetMetadata ¶
func (s *LocalService) GetMetadata() Metadata
GetMetadata 返回服务的元数据地图。 元数据是一个键值对映射,用于指定服务的额外属性。 md5:42fd4200585681c1
func (*LocalService) GetName ¶
func (s *LocalService) GetName() string
GetName 返回服务的名称。 名称对于服务是必需的,应在所有服务中保持唯一。 md5:c0cc1fa5e19d9a6c
func (*LocalService) GetPrefix ¶
func (s *LocalService) GetPrefix() string
GetPrefix 格式化并返回键前缀字符串。 结果前缀字符串通常用于服务注册服务器中的服务搜索。
以 etcd 服务器为例,前缀字符串的用法如下: `etcdctl get /services/prod/hello.svc --prefix` md5:3c443e018050694a
func (*LocalService) GetValue ¶
func (s *LocalService) GetValue() string
GetValue 格式化并返回服务的值。结果值通常用于键值注册服务器。 md5:81a88bc4bcc73037
func (*LocalService) GetVersion ¶
func (s *LocalService) GetVersion() string
GetVersion 返回服务的版本号。 建议使用GNU版本命名方式,例如:v1.0.0, v2.0.1, v2.1.0-rc。 服务可以同时部署多个版本。 如果服务中未设置版本,那么服务的默认版本为 "latest"。 md5:bf857eeaf16711ca
type Metadata ¶
type Metadata map[string]interface{}
Metadata 存储自定义的键值对。 md5:4a32feeda30a366c
type Registrar ¶
type Registrar interface { // Register将`service`注册到Registry中。 // 请注意,如果它使用自定义的服务修改了输入服务,它将返回一个新的Service。 // md5:f5dad972d06c6ae4 Register(ctx context.Context, service Service) (registered Service, err error) // 从注册表中注销离线服务,并移除 `service`。 md5:dff133d3dba9309d Deregister(ctx context.Context, service Service) error }
服务注册器的Registrar接口。 md5:524b709abe0ef38a
type Registry ¶
服务注册接口。 md5:ee4e4676007285d8
func GetRegistry ¶
func GetRegistry() Registry
GetRegistry 返回之前设置的默认Registry。如果没有设置Registry,它将返回nil。 md5:efe24f47351d5419
type SearchInput ¶
type SearchInput struct { Prefix string // Search by key prefix. Name string // 通过服务名称进行搜索。 md5:2d5eea224c638808 Version string // 通过服务版本搜索。 md5:b84dd2ba1226889a Metadata Metadata // 如果有多个结果,根据元数据进行过滤。 md5:96b1e7f8b8bddffa }
SearchInput 是用于服务搜索的输入参数。 md5:af7e87c98cbdc120
type Service ¶
type Service interface { // GetName 返回服务的名称。 // 服务名称是必需的,并且在所有服务中应具有唯一性。 // md5:0eed35abab84da2e GetName() string // GetVersion 返回服务的版本。建议使用类似于 v1.0.0、v2.0.1、v2.1.0-rc 的 GNU 版本命名法。一个服务可以同时部署多个版本。如果服务中未设置版本,那么默认版本为 "latest"。 // md5:17ba2c1584ea1bed GetVersion() string // GetKey 格式化并返回服务的唯一键字符串。这个结果键通常用于键值注册服务器。 // md5:b5f03cb2d5e4ec9b GetKey() string // GetValue 格式化并返回服务的值。 // 返回的结果值通常用于键值注册服务器。 // md5:4272ce46aece6a65 GetValue() string // GetPrefix 格式化并返回键的前缀字符串。 // 该前缀字符串常用于键值注册服务器中进行服务搜索。 // // 以 etcd 服务器为例,前缀字符串的使用方式如下: // `etcdctl get /services/prod/hello.svc --prefix` // md5:85bdda3bcce1a496 GetPrefix() string // GetMetadata 返回服务的元数据映射(Metadata)。元数据是一个键值对映射,用于指定服务的额外属性。 // md5:eb70e1f52cd809f7 GetMetadata() Metadata // GetEndpoints 返回服务的 Endpoints。Endpoints 包含服务的多个主机/端口信息。 // md5:7c1a630ab5b68b23 GetEndpoints() Endpoints }
服务接口,用于服务定义。 md5:e9dc084a14b9ab3c
func GetAndWatch ¶
GetAndWatch 用于获取服务并使用自定义的监视回调函数进行监视。 md5:9fa8d7df3bbbbe6d
func GetAndWatchWithDiscovery ¶
func GetAndWatchWithDiscovery(ctx context.Context, discovery Discovery, name string, watch ServiceWatch) (service Service, err error)
GetAndWatchWithDiscovery 用于在`discovery`中获取服务并使用自定义的观察回调函数。 md5:07dc90075ba8e7c6
func GetWithDiscovery ¶
func GetWithDiscovery(ctx context.Context, discovery Discovery, name string) (service Service, err error)
GetWithDiscovery 通过`discovery`中的服务名称检索并返回服务。 md5:f1ca28780ddf8348
func NewServiceWithKV ¶
NewServiceWithKV 使用键值对字符串创建并返回一个默认实现 Service 接口的服务。 md5:8789fc514001694f
func NewServiceWithName ¶
NewServiceWithName 根据服务名称创建并返回一个默认实现的 Service 接口实例。 md5:24c38960f0d05e58
type ServiceWatch ¶
type ServiceWatch func(service Service)
ServiceWatch 用于观察服务状态。 md5:075e96d2f9f06fe0