registry

package
v0.0.0-...-aadf7d6 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2021 License: GPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package registry is an interface for service discovery

Index

Constants

View Source
const (
	// GlobalDomain indicates any domain
	GlobalDomain = "*"
	// DefaultDomain to use if none was provided in options
	DefaultDomain = "nitro"
)

Variables

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

Functions

This section is empty.

Types

type AddOption

type AddOption func(*AddOptions)

func AddContext

func AddContext(ctx context.Context) AddOption

func AddDomain

func AddDomain(d string) AddOption

func AddTTL

func AddTTL(t time.Duration) AddOption

type AddOptions

type AddOptions struct {
	TTL time.Duration
	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
	// Domain to register the service in
	Domain string
}

type App

type App struct {
	Name     string            `json:"name"`
	Version  string            `json:"version"`
	Metadata map[string]string `json:"metadata"`
	// 在注册Handler的时候,Handler是一个命名类型,它有多个方法,每个方法对应一个Endpoint
	// Endpoint是率属于微服务的,Endpoint的具体执行者是多个Instance中的某一个
	Endpoints []*Endpoint `json:"endpoints"`
	// 每个微服务下可能有多个Instance,多个Instance之间使用负责均衡
	Instances []*Instance `json:"instances"`
}

微服务

type Endpoint

type Endpoint struct {
	// Name表示方法名
	Name     string            `json:"name"`
	Request  *Value            `json:"request"`
	Response *Value            `json:"response"`
	Metadata map[string]string `json:"metadata"`
}

type GetOption

type GetOption func(*GetOptions)

func GetContext

func GetContext(ctx context.Context) GetOption

func GetDomain

func GetDomain(d string) GetOption

type GetOptions

type GetOptions struct {
	Context context.Context
	// Domain to scope the request to
	Domain string
}

type Instance

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

type ListOption

type ListOption func(*ListOptions)

func ListContext

func ListContext(ctx context.Context) ListOption

func ListDomain

func ListDomain(d string) ListOption

type ListOptions

type ListOptions struct {
	Context context.Context
	// Domain to scope the request to
	Domain string
}

type Option

type Option func(*Options)

func Addrs

func Addrs(addrs ...string) Option

Addrs is the registry addresses to use

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

type Options

type Options struct {
	Addrs     []string
	Timeout   time.Duration
	Secure    bool
	TLSConfig *tls.Config
	// Other options for implementations of the interface
	// can be stored in a context
	Context context.Context
}

type RemoveOption

type RemoveOption func(*RemoveOptions)

func RemoveContext

func RemoveContext(ctx context.Context) RemoveOption

func RemoveDomain

func RemoveDomain(d string) RemoveOption

type RemoveOptions

type RemoveOptions struct {
	Context context.Context
	// Domain the service was registered in
	Domain string
}

type Result

type Result struct {
	Action string
	App    *App
}

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

type Table

type Table interface {
	Init(...Option) error
	Options() Options
	Add(*App, ...AddOption) error
	Remove(*App, ...RemoveOption) error
	Get(string, ...GetOption) ([]*App, error)
	List(...ListOption) ([]*App, error)
	Watch(...WatchOption) (Watcher, error)
	String() string
}

The registry provides an interface for service discovery and an abstraction over varying implementations {consul, etcd, zookeeper, ...}

type Value

type Value struct {
	// Type Name
	Name string `json:"name"`
	// Type Name
	Type string `json:"type"`
	// 如果是结构体,就存放各个字段的类型信息
	Values []*Value `json:"values"`
}

type WatchOption

type WatchOption func(*WatchOptions)

func WatchApp

func WatchApp(name string) WatchOption

Watch a service

func WatchContext

func WatchContext(ctx context.Context) WatchOption

func WatchDomain

func WatchDomain(d string) WatchOption

type WatchOptions

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

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 memory provides an in-memory registry
Package memory provides an in-memory registry

Jump to

Keyboard shortcuts

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