registry

package
v0.0.0-...-5237b18 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2021 License: Apache-2.0 Imports: 6 Imported by: 0

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

type CommonDiscoveryOption struct {
	DC   string
	Tags []string
}

=====================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 Event

type Event string
const (
	EventDegrade Event = "Degrade"
	EventRecover Event = "Recover"
)

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

func (*Service) ServiceIP

func (s *Service) ServiceIP() string

type ServiceCache

type ServiceCache struct {
	// contains filtered or unexported fields
}

func NewServiceCache

func NewServiceCache(cacher Cacher, interval time.Duration) *ServiceCache

func (*ServiceCache) Flush

func (c *ServiceCache) Flush() error

Flush 清空缓存

func (*ServiceCache) GetServices

func (c *ServiceCache) GetServices(key ServiceKey) ([]*Service, error)

func (*ServiceCache) Set

func (c *ServiceCache) Set(key ServiceKey, services []*Service)

type ServiceKey

type ServiceKey struct {
	Name string
	Tags string
	DC   string
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL