Documentation
¶
Index ¶
Constants ¶
const OptionKey = "options"
Variables ¶
This section is empty.
Functions ¶
func RegisterDriver ¶
RegisterDriver register a new Registry could be: conf.Configurable,and will be lazy loaded in server.Apply function
Types ¶
type DialOption ¶ added in v0.0.3
type DialOption interface {
// contains filtered or unexported methods
}
DialOption is the options for client dial when using registry resolver.
type DialOptions ¶ added in v0.0.3
type DialOptions struct { // namespace is the namespace of the service. Namespace string `json:"namespace" yaml:"namespace"` // ServiceName is the target server name, may omit leading slash ServiceName string `json:"serviceName" yaml:"serviceName"` // Version is the target server version, may omit leading slash Version string `json:"version" yaml:"version"` // Metadata holds the metadata of the service,registry driver parse it to match itself protocol Metadata map[string]string `json:"metadata" yaml:"metadata"` }
DialOptions is the options for client dial when using registry resolver. it includes the common options for service discovery and grpc dial.
func TargetToOptions
deprecated
added in
v0.0.3
func TargetToOptions(target resolver.Target) (*DialOptions, error)
TargetToOptions parse resolver target to DialOptions
Deprecated: registry driver should provide a function to instead
type Driver ¶ added in v0.0.3
type Driver interface { // CreateRegistry create a registry which for server side CreateRegistry(cnf *conf.Configuration) (Registry, error) // GetRegistry try to get a registry from driver cache. but driver may cache accord with some condition. GetRegistry(name string) (Registry, error) // ResolverBuilder returns a resolver.Builder for client side ResolverBuilder(cnf *conf.Configuration) (resolver.Builder, error) // WithDialOptions injects grpc.DialOption for grpc client dial if speciality of driver is needed. WithDialOptions(registryOpts DialOptions) ([]grpc.DialOption, error) }
Driver is the registry driver interface,it builds a registry for some kind of service discovery and resolver for grpc client.
usually, config contains a common config reference to a registry server config,thus use a single client. config like this:
registry: ref: some-registry-config # conf.Configuration path,start the root some-registry-config: scheme: etcd ... # etcd client config
func GetRegistry ¶
GetRegistry get a registry by scheme
type Registry ¶
type Registry interface { // Register a service node Register(*ServiceInfo) error // Unregister a service node Unregister(*ServiceInfo) error // TTL returns the time to live of the service node, if it is not available, return 0. // every tick will call Register function to refresh. TTL() time.Duration // Close release the resource Close() // GetServiceInfos returns the members of the cluster by service name // # Experimental // // notice: this function is a convenient function for consumer side, it is not a part of service discovery. GetServiceInfos(string) ([]*ServiceInfo, error) }
Registry provides an interface for service discovery
type ServiceInfo ¶ added in v0.0.3
type ServiceInfo struct { Name string `json:"name" yaml:"name"` Namespace string `json:"namespace" yaml:"namespace"` Version string `json:"version" yaml:"version"` Host string `json:"host" yaml:"host"` Port int `json:"port" yaml:"port"` Protocol string `json:"protocol" yaml:"protocol"` Metadata map[string]string `json:"metadata" yaml:"metadata"` }
ServiceInfo is the service information
func (ServiceInfo) Address ¶ added in v0.0.3
func (si ServiceInfo) Address() string
Address is the address of the service,example: host:port,ip:port
func (ServiceInfo) BuildKey ¶ added in v0.0.3
func (si ServiceInfo) BuildKey() string
func (ServiceInfo) ToAttributes ¶ added in v0.0.3
func (si ServiceInfo) ToAttributes() *attributes.Attributes
ToAttributes convert metadata to grpc attributes