naming

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2020 License: MIT Imports: 10 Imported by: 0

README

naming

项目简介

服务发现、服务注册相关的SDK集合

现状

目前默认实现了B站开源的Discovery服务注册与发现SDK。 但在使用之前,请确认discovery服务部署完成,并将该discovery.go内fixConfig方法的默认配置进行完善。

使用

可实现naming内的Builder&Resolver&Registry接口用于服务注册与发现,比如B站内部还实现了zk的。

Documentation

Index

Constants

View Source
const (
	MetaWeight  = "weight"
	MetaCluster = "cluster"
	MetaZone    = "zone"
	MetaColor   = "color"
)

metadata common key

Variables

This section is empty.

Functions

This section is empty.

Types

type BuildOpt

type BuildOpt interface {
	Apply(*BuildOptions)
}

BuildOpt build option interface.

func Filter

func Filter(schema string, clusters map[string]struct{}) BuildOpt

Filter filter option.

func ScheduleNode

func ScheduleNode(clientZone string) BuildOpt

ScheduleNode ScheduleNode option.

func Subset

func Subset(defaultSize int) BuildOpt

Subset Subset option.

type BuildOptions

type BuildOptions struct {
	Filter     func(map[string][]*Instance) map[string][]*Instance
	Subset     func([]*Instance, int) []*Instance
	SubsetSize int
	ClientZone string
	Scheduler  func(*InstancesInfo) []*Instance
}

BuildOptions build options.

type Builder

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

Builder resolver builder.

type Instance

type Instance struct {
	// Region is region.
	Region string `json:"region"`
	// Zone is IDC.
	Zone string `json:"zone"`
	// Env prod/pre、uat/fat1
	Env string `json:"env"`
	// AppID is mapping servicetree appid.
	AppID string `json:"appid"`
	// Hostname is hostname from docker.
	Hostname string `json:"hostname"`
	// Addrs is the address of app instance
	// format: scheme://host
	Addrs []string `json:"addrs"`
	// Version is publishing version.
	Version string `json:"version"`
	// LastTs is instance latest updated timestamp
	LastTs int64 `json:"latest_timestamp"`
	// Metadata is the information associated with Addr, which may be used
	// to make load balancing decision.
	Metadata map[string]string `json:"metadata"`
	// Status instance status, eg: 1UP 2Waiting
	Status int64 `json:"status"`
}

Instance represents a server the client connects to.

type InstancesInfo

type InstancesInfo struct {
	Instances map[string][]*Instance `json:"instances"`
	LastTs    int64                  `json:"latest_timestamp"`
	Scheduler *Scheduler             `json:"scheduler"`
}

InstancesInfo instance info.

type Registry

type Registry interface {
	Register(ctx context.Context, ins *Instance) (cancel context.CancelFunc, err error)
	Close() error
}

Registry Register an instance and renew automatically.

type Resolver

type Resolver interface {
	Fetch(context.Context) (*InstancesInfo, bool)
	Watch() <-chan struct{}
	Close() error
}

Resolver resolve naming service

type Scheduler

type Scheduler struct {
	Clients map[string]*ZoneStrategy `json:"clients"`
}

Scheduler scheduler.

type Strategy

type Strategy struct {
	Weight int64 `json:"weight"`
}

Strategy is zone scheduling strategy.

type ZoneStrategy

type ZoneStrategy struct {
	Zones map[string]*Strategy `json:"zones"`
}

ZoneStrategy is the scheduling strategy of all zones

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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