Documentation ¶
Index ¶
- func GetNameID(etcdKey string) (name, id string)
- func RandomPermPolicy(l []ServiceRegister) interface{}
- func RandomPolicy(l []ServiceRegister) interface{}
- type BalancerFunc
- type ConfigInfo
- type ConfigSlice
- type ConfigStringMap
- type DB
- func (e *DB) Close() error
- func (e *DB) Configuring(conf ConfigInfo, setFunc SetConfFunc, watcher ...WatcherFunc) error
- func (e *DB) DelServiceList(name, id string)
- func (e *DB) DelServiceListing(key string)
- func (e *DB) Deregister() error
- func (e *DB) Discover(service ServiceInfo) error
- func (e *DB) GetConfigs() ConfigStringMap
- func (e *DB) GetConn() *clientV3.Client
- func (e *DB) GetRepo() *DB
- func (e *DB) GetService(s ServiceInfo, balancer ...BalancerFunc) ServiceInfo
- func (e *DB) GetServiceArray(s ServiceInfo, balancer ...BalancerFunc) []ServiceInfo
- func (e *DB) GetServiceListing() ServiceListing
- func (e *DB) IsDiscovered() bool
- func (e *DB) IsRegistered() bool
- func (e *DB) ListenKeepAlive()
- func (e *DB) Register(service *ServiceInfo) error
- func (e *DB) SetConfig(key string, val []byte, listing ...ConfigStringMap)
- func (e *DB) SetServiceListing(val []byte) error
- func (e *DB) ThisService() ServiceRegister
- func (e *DB) TimeOutCtx(ttl int) (ctx context.Context, cancel context.CancelFunc)
- func (e *DB) Watcher(prefix string, watcherFunc WatcherFunc)
- type Info
- type Repo
- type ServiceInfo
- type ServiceListing
- type ServiceRegister
- type SetConfFunc
- type WatcherFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RandomPermPolicy ¶
func RandomPermPolicy(l []ServiceRegister) interface{}
func RandomPolicy ¶
func RandomPolicy(l []ServiceRegister) interface{}
Types ¶
type BalancerFunc ¶
type BalancerFunc func([]ServiceRegister) interface{}
func MetaPermPolicy ¶
func MetaPermPolicy(meta map[string]string) BalancerFunc
func MetaPolicy ¶
func MetaPolicy(meta map[string]string) BalancerFunc
type ConfigInfo ¶
type ConfigInfo ServiceInfo
func (*ConfigInfo) SetPrefix ¶
func (c *ConfigInfo) SetPrefix()
type ConfigSlice ¶
type ConfigSlice []interface{}
type ConfigStringMap ¶
type ConfigStringMap map[string]interface{}
type DB ¶
type DB struct { ConfigInfo ConfigInfo Service ServiceRegister GrpcService ServiceRegister Logger *zap.Logger // contains filtered or unexported fields }
func (*DB) Configuring ¶
func (e *DB) Configuring(conf ConfigInfo, setFunc SetConfFunc, watcher ...WatcherFunc) error
Configuring watcher 可以不传, 会有默认值. 如果要传的话, 只接受一个函数, 多传无效.
func (*DB) DelServiceList ¶
func (*DB) Discover ¶
func (e *DB) Discover(service ServiceInfo) error
Discover 服务发现, 核心参数是 ServiceInfo.Namespace, ServiceInfo.ProjectName, ServiceInfo.ProjectVersion, ServiceInfo.Version 这四个
func (*DB) GetConfigs ¶
func (e *DB) GetConfigs() ConfigStringMap
func (*DB) GetService ¶
func (e *DB) GetService(s ServiceInfo, balancer ...BalancerFunc) ServiceInfo
GetService 一个负载均衡的服务获取, 默认为随机策略, 如果传了ServiceInfo.Meta参数, 则使用Meta匹配策略来寻找服务, 传进来的BalancerFunc会失效.
func (*DB) GetServiceArray ¶
func (e *DB) GetServiceArray(s ServiceInfo, balancer ...BalancerFunc) []ServiceInfo
GetServiceArray 获取一个按负载俊航策略排序的服务列表, 默认为随机策略, 如果传了ServiceInfo.Meta参数, 则使用Meta匹配策略来寻找服务, 传进来的BalancerFunc会失效
func (*DB) GetServiceListing ¶
func (e *DB) GetServiceListing() ServiceListing
func (*DB) IsDiscovered ¶
func (*DB) IsRegistered ¶
func (*DB) Register ¶
func (e *DB) Register(service *ServiceInfo) error
Register 使用etcd租约模式注册服务, meta可以不传, 如果传的话只传一个, 多传无效.
func (*DB) SetConfig ¶
func (e *DB) SetConfig(key string, val []byte, listing ...ConfigStringMap)
SetConfig 新增配置项.
func (*DB) SetServiceListing ¶
SetServiceListing 新增服务地址
func (*DB) ThisService ¶
func (e *DB) ThisService() ServiceRegister
func (*DB) TimeOutCtx ¶
func (*DB) Watcher ¶
func (e *DB) Watcher(prefix string, watcherFunc WatcherFunc)
type Info ¶
type Info struct { // Endpoints is a list of URLs. Endpoints []string `toml:"Endpoints" json:"Endpoints"` // DialTimeout is the timeout for failing to establish a connection. DialTimeout int64 `toml:"DialTimeout" json:"DialTimeout"` // DialKeepAliveTimeout is the time that the client waits for a response for the // keep-alive probe. If the response is not received in this time, the connection is closed. DialKeepAliveTimeout time.Duration `toml:"DialKeepAliveTimeout" json:"DialKeepAliveTimeout"` // MaxCallSendMsgSize is the client-side request send limit in bytes. // If 0, it defaults to 2.0 MiB (2 * 1024 * 1024). // Make sure that "MaxCallSendMsgSize" < server-side default send/recv limit. // ("--max-request-bytes" flag to etcd or "embed.Config.MaxRequestBytes"). MaxCallSendMsgSize int `toml:"MaxCallSendMsgSize" json:"MaxCallSendMsgSize"` // MaxCallRecvMsgSize is the client-side response receive limit. // If 0, it defaults to "math.MaxInt32", because range response can // easily exceed request send limits. // Make sure that "MaxCallRecvMsgSize" >= server-side default send/recv limit. // ("--max-request-bytes" flag to etcd or "embed.Config.MaxRequestBytes"). MaxCallRecvMsgSize int `toml:"MaxCallRecvMsgSize" json:"MaxCallRecvMsgSize"` // Username is a user name for authentication. Username string `toml:"Username" json:"Username"` // Password is a password for authentication. Password string `toml:"pwd" json:"pwd"` // RejectOldCluster when set will refuse to create a client against an outdated cluster. RejectOldCluster bool `toml:"RejectOldCluster" json:"RejectOldCluster"` // PermitWithoutStream when set will allow client to send keepalive pings to server without any active streams(RPCs). PermitWithoutStream bool `toml:"PermitWithoutStream" json:"PermitWithoutStream"` TLSCa string `toml:"TLSCa" json:"TLSCa"` TLSCert string `toml:"TLSCert" json:"TLSCert"` TLSCertKey string `toml:"TLSCertKey" json:"TLSCertKey"` // TLS holds the client secure credentials, if any. TLS *tls.Config }
type Repo ¶
type Repo interface { GetRepo() *DB GetConn() *clientV3.Client GetServiceListing() ServiceListing GetConfigs() ConfigStringMap TimeOutCtx(ttl int) (context.Context, context.CancelFunc) Watcher(prefix string, watcher WatcherFunc) Close() error Register(service *ServiceInfo) error ListenKeepAlive() Deregister() error ThisService() ServiceRegister IsRegistered() bool Discover(service ServiceInfo) error SetServiceListing(val []byte) error DelServiceListing(key string) GetService(s ServiceInfo, balancer ...BalancerFunc) ServiceInfo GetServiceArray(s ServiceInfo, balancer ...BalancerFunc) []ServiceInfo IsDiscovered() bool Configuring(conf ConfigInfo, setFunc SetConfFunc, watcher ...WatcherFunc) error SetConfig(key string, val []byte, listing ...ConfigStringMap) }
func CreateSpecialEtcd ¶
type ServiceInfo ¶
type ServiceInfo struct { // 一个uuid4, 存储在etcd中时, 作为key的后缀来使用. ID string `json:"ID"` // 命名空间, 用以区分环境. Namespace string `toml:"Namespace" json:"Namespace"` // 获取etcd域名 K8sDomain string `toml:"K8sDomain" json:"K8sDomain"` // 服务名称. Name string `toml:"Name" json:"Name"` // 用来在etcd中标识这个key是一个服务而不是一个配置 Prefix string `toml:"Prefix" json:"Prefix"` Addr string `toml:"Addr" json:"Addr"` Port int `toml:"Port" json:"Port"` TTL int64 `toml:"TTL" json:"TTL"` // 服务的协议, http, https, grpc Scheme string `toml:"Scheme" json:"Scheme"` // http用 HealthPath string `toml:"HealthPath" json:"HealthPath"` // grpc用 HealthMethod string `toml:"HealthMethod" json:"HealthMethod"` // 健康结果 HealthVerdict map[string]string `toml:"HealthVerdict" json:"HealthVerdict"` Meta map[string]string `toml:"Meta" json:"Meta"` // 自定义的api版本, 如v1, v2这样子. ApiVersion string `toml:"ApiVersion" json:"ApiVersion"` // etcd中的记录版本, 纯数字, 从1开始, 每修改一次则+1, 最大为1000 RecordVersion int64 // 轮询时的标记 PollingCount int64 // ProjectVersion 项目版本(注册中心用) ProjectVersion = "v2.0" ProjectVersion string `toml:"ProjectVersion" json:"ProjectVersion"` // ProjectName 项目名称(注册中心用) ProjectName = "xdr" ProjectName string `toml:"ProjectName" json:"ProjectName"` Listen string `toml:"Listen" json:"Listen"` }
func CreateSpecialServiceInfo ¶
func CreateSpecialServiceInfo(dev, serviceName string) *ServiceInfo
func (*ServiceInfo) SetDefaultTTL ¶
func (i *ServiceInfo) SetDefaultTTL()
func (*ServiceInfo) SetID ¶
func (i *ServiceInfo) SetID() error
func (*ServiceInfo) SetPrefix ¶
func (i *ServiceInfo) SetPrefix()
func (ServiceInfo) Url ¶
func (i ServiceInfo) Url() string
type ServiceListing ¶
type ServiceListing map[string]map[string][]ServiceRegister
type ServiceRegister ¶
type ServiceRegister struct { Key string `json:"register_key"` Val ServiceInfo `json:"register_val"` }
func (*ServiceRegister) SetKey ¶
func (r *ServiceRegister) SetKey()
type SetConfFunc ¶
type SetConfFunc func(Repo, clientV3.GetResponse)
type WatcherFunc ¶
type WatcherFunc func(Repo, clientV3.WatchResponse)
Click to show internal directories.
Click to hide internal directories.