Documentation ¶
Overview ¶
Micro Service Discovery Author: Vincent Young Version: v1.0.0
Based: Etcd EtcdKeyRule: /{Prefix}/{SupportService}/{ServiceAddr}
Support: 1. Load Balance Strategy: polling、random 2. Auto find the normal node 3. Multi services 4. Service cluster 5. Optional etcd prefix
TODO: 1. Discover center cluster 2. Etcd value more service info (v1.0.0: Only addr string) 3. Optional service (v1.0.0: Need to hard code in discovery file) 4. Optimize error output 5. Add get all services method, so can implement load balance out of discovery (v1.0.0: Load balance in discovery)
Index ¶
Constants ¶
View Source
const ( ServiceEnvTest = "test" ServiceEnvOnline = "online" )
Variables ¶
This section is empty.
Functions ¶
func RunDiscovery ¶
func RunDiscovery(config *DiscoveryConfig)
func RunRegister ¶
func RunRegister(config *RegisterConfig)
Types ¶
type Discovery ¶
type Discovery struct { Env ServiceEnv // contains filtered or unexported fields }
var D *Discovery
func (*Discovery) GetService ¶
func (d *Discovery) GetService(s SupportService) (addr string)
func (*Discovery) SetLoadBalance ¶
func (d *Discovery) SetLoadBalance(lb SupportLoadBalance)
func (*Discovery) UpdateServiceStatus ¶
func (d *Discovery) UpdateServiceStatus(s SupportService, addr string, status ServiceStatus)
type DiscoveryConfig ¶ added in v0.0.6
type DiscoveryConfig struct { Host string `yaml:"Host"` Port int `yaml:"Port"` Prefix string `yaml:"Prefix"` Env ServiceEnv `yaml:"Env"` LoadBalance SupportLoadBalance `yaml:"LoadBalance"` }
type RegisterConfig ¶ added in v0.0.6
type Service ¶
type Service struct { Env ServiceEnv Name SupportService Addr string Status ServiceStatus }
type ServiceEnv ¶ added in v0.0.6
type ServiceEnv string
type ServiceMap ¶
type ServiceMap map[ServiceEnv]map[SupportService][]*Service
func NewServiceMap ¶ added in v0.0.6
func NewServiceMap(env ServiceEnv) ServiceMap
type ServiceStatus ¶
type ServiceStatus int
const ( ServiceStatusNormal ServiceStatus = 1 ServiceStatusFailure ServiceStatus = 0 )
type SupportLoadBalance ¶
type SupportLoadBalance int
const ( SupportLoadBalancePolling SupportLoadBalance = iota SupportLoadBalanceRandom )
type SupportService ¶
type SupportService string
const ( SupportServiceGood SupportService = "good" SupportServiceAddress SupportService = "address" )
Click to show internal directories.
Click to hide internal directories.