Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cacher ¶
type Cacher interface { LastModify(ServiceKey) (time.Time, error) Store(ServiceKey, interface{}) error }
Cacher represents cache interface of service.
type CommonDiscoveryOption ¶
=====================discovery=====================
func NewCommonDiscoveryOption ¶
func NewCommonDiscoveryOption(opts ...DiscoveryOption) *CommonDiscoveryOption
type Discovery ¶
type Discovery interface { GetServices(string, ...DiscoveryOption) ([]*Service, error) Notify(event Event) Watch(Watcher) Close() }
Discovery represents resolver interface.
type DiscoveryOpt ¶
type DiscoveryOpt func(*CommonDiscoveryOption)
func WithDC ¶
func WithDC(dc string) DiscoveryOpt
func WithTags ¶
func WithTags(tags []string) DiscoveryOpt
func (DiscoveryOpt) IsDiscovery ¶
func (DiscoveryOpt) IsDiscovery()
type DiscoveryOption ¶
type DiscoveryOption interface {
IsDiscovery()
}
type Service ¶
type Service struct { ID string `discovery:"可选,服务id"` Name string `discovery:"必填,服务名"` IP string `discovery:"可选,默认拿en0的地址"` IPTemplate string `discovery:"可选,可以用于指定特殊网卡" json:"IPTemplate,omitempty"` Tags []string `discovery:"可选,标签"` Port int `discovery:"必填,端口"` Weight int32 `discovery:"可选,权重"` Meta map[string]string `discovery:"可选,自定义元数据"` // contains filtered or unexported fields }
Service
type ServiceCache ¶
type ServiceCache struct {
// contains filtered or unexported fields
}
func NewServiceCache ¶
func NewServiceCache(cacher Cacher, interval time.Duration) *ServiceCache
func (*ServiceCache) GetServices ¶
func (c *ServiceCache) GetServices(key ServiceKey) ([]*Service, error)
func (*ServiceCache) Set ¶
func (c *ServiceCache) Set(key ServiceKey, services []*Service)
type ServiceKey ¶
ServiceKey defines service with query meta
func NewServiceKey ¶
func NewServiceKey(name string, tags []string, dc string) ServiceKey
func ParseServiceKey ¶
func ParseServiceKey(key string) (*ServiceKey, error)
key formatted in [<tags>.]<service name>.service.[.<consul datacenter>]
func (*ServiceKey) ToString ¶
func (key *ServiceKey) ToString() string
type WatchFunc ¶
type WatchFunc func(ServiceKey, []*Service)
WatchFunc wraps given func as Watcher interface.
func (WatchFunc) Handle ¶
func (f WatchFunc) Handle(serviceKey ServiceKey, services []*Service)
type Watcher ¶
type Watcher interface {
Handle(ServiceKey, []*Service)
}
Watcher represents a callback for service key.
Click to show internal directories.
Click to hide internal directories.