etcd

package
v0.0.0-...-abc1ebd Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GRegistry = NewRegistry()

Functions

func GenKey

func GenKey(projectName string, etcdWatchMsgType string, groupID uint32, serviceName string, serviceID uint32) string

func GenPrefixKey

func GenPrefixKey(projectName string) string

func Parse

func Parse(key string) (msgType string, groupID uint32, serviceName string, serviceID uint32)

Parse 解析key

func ValueJson2String

func ValueJson2String(valueJson *ValueJson) string

Types

type Etcd

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

func NewEtcd

func NewEtcd(opts ...*Options) *Etcd

func (*Etcd) DelWithPrefix

func (p *Etcd) DelWithPrefix(keyPrefix string) (*etcdclientv3.DeleteResponse, error)

DelWithPrefix 删除键值 匹配的键值

func (*Etcd) GetKey

func (p *Etcd) GetKey() string

func (*Etcd) GetPrefix

func (p *Etcd) GetPrefix(key string) (*etcdclientv3.GetResponse, error)

GetPrefix 查找以key为前缀的所有 key value

func (*Etcd) GetPrefixIntoChan

func (p *Etcd) GetPrefixIntoChan() (err error)

GetPrefixIntoChan 取得关心的前缀,放入 chan 中

func (*Etcd) KeepAlive

func (p *Etcd) KeepAlive(ctx context.Context) error

KeepAlive 更新租约

func (*Etcd) PutWithLease

func (p *Etcd) PutWithLease(key string, value string) (*etcdclientv3.PutResponse, error)

PutWithLease 将一个键值对放入etcd中 WithLease 带ttl

func (*Etcd) Start

func (p *Etcd) Start(ctx context.Context, value string) error

Start 开始

func (*Etcd) Stop

func (p *Etcd) Stop() error

Stop 停止

func (*Etcd) WatchPrefix

func (p *Etcd) WatchPrefix(key string) etcdclientv3.WatchChan

WatchPrefix 监视以key为前缀的所有 key value

func (*Etcd) WatchPrefixIntoChan

func (p *Etcd) WatchPrefixIntoChan() (err error)

WatchPrefixIntoChan 监听key变化,放入 chan 中

type GrpcService

type GrpcService struct {
	PackageName *string `json:"packageName,omitempty"` // 包名
	ServiceName *string `json:"serviceName,omitempty"` // 服务名称
	Addr        *string `json:"addr,omitempty"`        // 服务地址 e.g.: 127.0.0.1:8989 [default]: ""
}

type IEtcd

type IEtcd interface {
	Start(ctx context.Context, value string) error
	Stop() error
	GetKey() string
	PutWithLease(key string, value string) (*etcdclientv3.PutResponse, error)
	KeepAlive(ctx context.Context) error
}
var GEtcd IEtcd

type Options

type Options struct {
	AddCallback    xcontrol.ICallBack // 增加回调 [default: nil]
	UpdateCallback xcontrol.ICallBack // 更新回调 [default: nil]
	DelCallback    xcontrol.ICallBack // 删除回调 [default: nil]
	// contains filtered or unexported fields
}

func MergeOptions

func MergeOptions(opts ...*Options) *Options

func NewOptions

func NewOptions() *Options

NewOptions 新的Options

func (*Options) GetKey

func (p *Options) GetKey() string

func (*Options) WithAddCallback

func (p *Options) WithAddCallback(callback xcontrol.ICallBack) *Options

func (*Options) WithDelCallback

func (p *Options) WithDelCallback(callback xcontrol.ICallBack) *Options

func (*Options) WithDialTimeout

func (p *Options) WithDialTimeout(dialTimeout time.Duration) *Options

func (*Options) WithEndpoints

func (p *Options) WithEndpoints(endpoints []string) *Options

func (*Options) WithGrantLeaseMaxRetries

func (p *Options) WithGrantLeaseMaxRetries(retries int) *Options

func (*Options) WithIOut

func (p *Options) WithIOut(iOut xcontrol.IOut) *Options

func (*Options) WithKey

func (p *Options) WithKey(key string) *Options

func (*Options) WithTTL

func (p *Options) WithTTL(ttl int64) *Options

func (*Options) WithUpdateCallback

func (p *Options) WithUpdateCallback(callback xcontrol.ICallBack) *Options

func (*Options) WithWatchKeyPrefix

func (p *Options) WithWatchKeyPrefix(watchKeyPrefix string) *Options

type Registry

type Registry struct {
	DataMap *xmap.MapMutexMgr[string, *ValueJson]
}

记录-服务信息

func NewRegistry

func NewRegistry() *Registry

func (*Registry) Find

func (p *Registry) Find(key string) (*ValueJson, bool)

func (*Registry) FindByGroupName

func (p *Registry) FindByGroupName(groupID uint32, serviceName string) []*ServiceInfo

func (*Registry) FindByGroupNameID

func (p *Registry) FindByGroupNameID(groupID uint32, serviceName string, serviceID uint32) []*ValueJson

func (*Registry) Update

func (p *Registry) Update(key string, value *ValueJson)

type ServerNet

type ServerNet struct {
	Addr *string `json:"addr"`           // e.g.: 127.0.0.1:8989 [default]: ""
	Name *string `json:"name,omitempty"` // 链接名称 [default]: ""
	Type *string `json:"type"`           // [tcp, kcp] [default]: xnetcommon.ServerNetTypeNameTCP
}

type ServiceInfo

type ServiceInfo struct {
	ServiceID   uint32
	ServiceName string
	ValueJson   *ValueJson
}

type ValueJson

type ValueJson struct {
	ServerNet     []*ServerNet `json:"serverNet,omitempty"`     // 有:直接使用. 没有:使用 etcd.ServerNet
	Version       string       `json:"version,omitempty"`       // 有:直接使用. 没有:使用 base.version 生成
	AvailableLoad uint32       `json:"availableLoad,omitempty"` // 剩余可用负载, 可用资源数
	SecondOffset  int64        `json:"secondOffset,omitempty"`  // 服务 时间(秒)偏移量
	GrpcService   *GrpcService `json:"grpcService,omitempty"`   // gRPC 服务信息
}

ValueJson etcd 通讯的数据,由服务中的数据生成,定时更新->etcd->服务

func ValueString2Json

func ValueString2Json(value string) *ValueJson

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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