registry

package
v0.0.0-...-5e9c659 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

README

注册中心

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound       = errors.New("service not found") // Not found error when GetService is called
	ErrWatcherStopped = errors.New("watcher stopped")   // Watcher stopped error when watcher is stopped

)

Functions

func Logger

func Logger() logger.ILogger

func Register

func Register(name string, creator func(opts ...Option) IRegistry)

Types

type Config

type Config struct {
	config.Config `field:"-"`
	Name          string          `field:"-"` //
	PrefixName    string          `field:"-"` // config prefix name/path in config file
	Logger        logger.ILogger  `field:"-"` // 实例
	Context       context.Context `field:"-"`
	LocalServices []*Service      `field:"-"` // current service information
	Addrs         []string        `field:"-"`
	TlsConfig     *tls.Config     `field:"-"`

	Timeout time.Duration
	Secure  bool
	TTL     time.Duration `field:"ttl"`
}

func NewConfig

func NewConfig(opts ...Option) *Config

new and init a config

func (*Config) Init

func (self *Config) Init(opts ...Option)

func (*Config) Load

func (self *Config) Load() error

func (*Config) Save

func (self *Config) Save(immed ...bool) error

func (*Config) String

func (self *Config) String() string

type DeregisterConfig

type DeregisterConfig struct {
	Context context.Context
}

type Endpoint

type Endpoint struct {
	// RPC Method e.g. Greeter.Hello
	Name string `json:"name"`
	// HTTP Host e.g example.com
	Host []string `json:"host"`
	// HTTP Methods e.g GET, POST
	Method []string `json:"method"`
	// HTTP Path e.g /greeter. Expect POSIX regex
	Path string `json:"path"`
	// Description e.g what's this endpoint for
	Description string `json:"description"`
	// Stream flag
	Stream bool `json:"stream"`

	// 以下待确认
	Request  *Value            `json:"request"`
	Response *Value            `json:"response"`
	Metadata map[string]string `json:"metadata"`

	// API Handler e.g rpc, proxy
	Handler string
	// Body destination
	// "*" or "" - top level message value
	// "string" - inner message value
	Body string
}

type Event

type Event struct {
	// Id is registry id
	Id string
	// Type defines type of event
	Type EventType
	// Timestamp is event timestamp
	Timestamp time.Time
	// Service is registry service
	Service *Service
}

Event is registry event

type EventType

type EventType int

EventType defines registry event type

const (
	// Create is emitted when a new service is registered
	Create EventType = iota
	// Delete is emitted when an existing service is deregsitered
	Delete
	// Update is emitted when an existing servicec is updated
	Update
)

func (EventType) String

func (t EventType) String() string

String returns human readable event type

type GetConfig

type GetConfig struct {
	Context context.Context
}

type IRegistry

type IRegistry interface {
	Init(...Option) error
	Config() *Config
	Register(*Service, ...Option) error   // 注册
	Deregister(*Service, ...Option) error // 注销
	GetService(string) ([]*Service, error)
	ListServices() ([]*Service, error)
	Watcher(...WatchOptions) (Watcher, error)
	LocalServices() []*Service
	String() string
}

注册中心接口

func Default

func Default(new ...IRegistry) IRegistry

NopRegistry as default registry

func Use

func Use(name string, opts ...Option) IRegistry

type ListConfig

type ListConfig struct {
	Context context.Context
}

type Node

type Node struct {
	Id       string            `json:"id"`
	Address  string            `json:"address"`
	Metadata map[string]string `json:"metadata"`
}

微服务节点 相当于每个程序/Port一个节点

type Option

type Option func(*Config)

func Addrs

func Addrs(addrs ...string) Option

Addrs is the registry addresses to use

func Debug

func Debug() Option

func RegisterTTL

func RegisterTTL(t time.Duration) Option

func Secure

func Secure(b bool) Option

Secure communication with the registry

func TLSConfig

func TLSConfig(t *tls.Config) Option

Specify TLS Config

func Timeout

func Timeout(t time.Duration) Option

func WithConfigPrefixName

func WithConfigPrefixName(prefixName string) Option

修改Config.json的路径

func WithName

func WithName(name string) Option

change registry name

type RegisterConfig

type RegisterConfig struct {
	TTL time.Duration
	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
}

type Result

type Result struct {
	Action  string
	Service *Service
}

Result is returned by a call to Next on the watcher. Actions can be create, update, delete

type Service

type Service struct {
	Name      string            `json:"name"`
	Version   string            `json:"version"`
	Metadata  map[string]string `json:"metadata"`
	Endpoints []*Endpoint       `json:"endpoints"`
	Nodes     []*Node           `json:"nodes"`
}

微服务

func (*Service) Equal

func (self *Service) Equal(to *Service) bool

比对服务节点UID是否一致,

type Value

type Value struct {
	Name   string   `json:"name"`
	Type   string   `json:"type"`
	Values []*Value `json:"values"`
}

type WatchConfig

type WatchConfig struct {
	// Specify a service to watch
	// If blank, the watch is for all services
	Service string
	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
}

type WatchOptions

type WatchOptions func(*WatchConfig) error

type Watcher

type Watcher interface {
	// Next is a blocking call
	Next() (*Result, error)
	Stop()
}

Watcher is an interface that returns updates about services within the registry.

Directories

Path Synopsis
Package cache provides a registry cache
Package cache provides a registry cache
Package etcd provides an etcd service registry
Package etcd provides an etcd service registry

Jump to

Keyboard shortcuts

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