naming

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusUp   = 0
	StatusDown = 1

	GroupID       = "TSF_GROUP_ID"
	NamespaceID   = "TSF_NAMESPACE_ID"
	ApplicationID = "TSF_APPLICATION_ID"

	NsLocal  = "local"
	NsGlobal = "global"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type BuildOpt

type BuildOpt interface {
	Apply(*BuildOptions)
}

BuildOpt build option interface.

type BuildOptions

type BuildOptions struct {
}

BuildOptions build options.

type Builder

type Builder interface {
	Build(id string, options ...BuildOpt) Watcher
	Scheme() string
}

Builder resolver builder.

type Discovery

type Discovery interface {
	// 根据namespace,service name非阻塞获取服务信息,并返回是否初始化过
	Fetch(svc Service) ([]Instance, bool)
	// 根据namespace,service name订阅服务信息,直到服务有更新或超时返回(如果超时则success=false)
	Subscribe(svc Service) Watcher
	// discovery Scheme
	Scheme() string
}

Discovery 服务发现

type Instance

type Instance struct {
	// 服务信息
	Service *Service `json:"service,omitempty"`
	// namespace下全局唯一的实例ID
	ID string `json:"id"`
	// 服务实例所属地域
	Region string `json:"region"`
	// 服务实例可访问的ip地址
	Host string `json:"addrs"`
	// 协议端口
	Port int `json:"port"`
	// 服务实例标签元信息,比如appVersion、group、weight等
	Metadata map[string]string `json:"metadata"`
	// 实例运行状态: up/down
	Status int64 `json:"status"`
	// 过滤用的标签
	Tags []string
}

Instance 服务实例信息

func (Instance) Addr

func (i Instance) Addr() string

type Registry

type Registry interface {
	// 注册实例
	Register(ins *Instance) error
	// 注销实例
	Deregister(ins *Instance) error
}

Registry 注册中心

type Service

type Service struct {
	Namespace string
	Name      string
}

Service 服务信息

func NewService

func NewService(namespace string, name string) Service

type Watcher

type Watcher interface {
	//第一次访问的时候如果有值立马返回cfg,后面watch的时候有变更才返回
	//如果超时或者被Close应当抛出错误
	Watch(ctx context.Context) ([]Instance, error)
	//如果不需要使用则关闭订阅
	Close()
}

Watcher 消息订阅

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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