discovery

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2019 License: MIT Imports: 7 Imported by: 10

Documentation

Index

Constants

View Source
const (
	// 不能直接保存二进制,底层用Json转base64,base64的二进制比原二进制要大最终二进制不到512K就会达到限制
	PackedValueSize = 300 * 1024
)

KV中的Value最大不超过512K,

Variables

This section is empty.

Functions

func AnyToBytes

func AnyToBytes(data interface{}, prettyPrint bool) ([]byte, error)

func BytesToAny

func BytesToAny(data []byte, dataPtr interface{}) error

func SafeGetValue

func SafeGetValue(sd Discovery, key string, valuePtr interface{}, decompress bool) error

func SafeSetValue

func SafeSetValue(sd Discovery, key string, value interface{}, compress bool) error

compress value按 key, key.1, key.2 ... 保存

func ValueMetaToSlice

func ValueMetaToSlice(pairs []ValueMeta, dataPtr interface{}) error

Types

type CheckerFunc

type CheckerFunc func() (output, status string)

type Discovery

type Discovery interface {

	// 注册服务
	Register(*ServiceDesc) error

	// 解注册服务
	Deregister(svcid string) error

	// 根据服务名查到可用的服务
	Query(name string) (ret []*ServiceDesc)

	// 注册服务变化通知
	RegisterNotify(mode string) (ret chan struct{})

	// 解除服务变化通知
	DeregisterNotify(mode string, c chan struct{})

	// 设置值
	SetValue(key string, value interface{}, optList ...interface{}) error

	// 取值,并赋值到变量
	GetValue(key string, valuePtr interface{}) error

	// 删除值
	DeleteValue(key string) error
}
var (
	Default Discovery
)

type ServiceDesc

type ServiceDesc struct {
	Name string
	ID   string // 所有service中唯一的id
	Host string
	Port int
	Tags []string          // 分类标签
	Meta map[string]string // 细节配置
}

注册到服务发现的服务描述

func (*ServiceDesc) Address

func (self *ServiceDesc) Address() string

func (*ServiceDesc) ContainTags

func (self *ServiceDesc) ContainTags(tag string) bool

func (*ServiceDesc) Equals

func (self *ServiceDesc) Equals(sd *ServiceDesc) bool

func (*ServiceDesc) FormatString

func (self *ServiceDesc) FormatString() string

func (*ServiceDesc) GetMeta

func (self *ServiceDesc) GetMeta(name string) string

func (*ServiceDesc) GetMetaAsInt

func (self *ServiceDesc) GetMetaAsInt(name string) int

func (*ServiceDesc) SetMeta

func (self *ServiceDesc) SetMeta(key, value string)

func (*ServiceDesc) String

func (self *ServiceDesc) String() string

type ValueMeta

type ValueMeta struct {
	Key   string
	Value []byte
}

Directories

Path Synopsis
api
proto
Generated by github.com/davyxu/protoplus DO NOT EDIT!
Generated by github.com/davyxu/protoplus DO NOT EDIT!

Jump to

Keyboard shortcuts

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