store

package
v0.0.0-...-276be26 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2019 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DEFAULT_CONSUL_HOST      = "consul.ops.local"
	DEFAULT_CONSUL_LOCALHOST = "localhost"
	DEFAULT_CONSUL_PORT      = 8500
	DEFAULT_CONSUL_SCHEME    = "http"

	SERVICE_CONSUL_API = "consulapi"
	SERVICE_DB         = "test-rds"
	SERVICE_MQ         = "test-mq"
	SERVICE_CACHE      = "test-redis"

	KEY_WAS_SETUP   = "ops/config/common"
	VALUE_WAS_SETUP = "---"
)

Variables

View Source
var (
	DefaultConsulConfig = ConsulConfig{
		Scheme:   DEFAULT_CONSUL_SCHEME,
		Addr:     "127.0.0.1:8500",
		Insecure: true,
	}
)
View Source
var Event_EventType_name = map[Event_EventType]string{
	PUT:    "PUT",
	DELETE: "DELETE",
}
View Source
var Event_EventType_value = map[string]Event_EventType{
	"PUT":    PUT,
	"DELETE": DELETE,
}

Functions

func EvTypeToString

func EvTypeToString(evType Event_EventType) string

Types

type ConsulConfig

type ConsulConfig struct {
	Scheme                         string `json:"scheme,omitempty" yaml:"scheme,omitempty"`
	Addr                           string `json:"addr" yaml:"addr"`
	Insecure                       bool   `json:"insecure,omitempty" yaml:"insecure,omitempty"`
	CertFile                       string `json:"cert,omitempty" yaml:"cert,omitempty"`
	KeyFile                        string `json:"key,omitempty" yaml:"key,omitempty"`
	CACertFile                     string `json:"cacert,omitempty" yaml:"cacert,omitempty"`
	Username                       string `json:"username,omitempty" yaml:"username,omitempty"`
	Password                       string `json:"password,omitempty" yaml:"password,omitempty"`
	Root                           string `json:"root,omitempty" yaml:"root,omitempty"`
	DeregisterCriticalServiceAfter string `json:"deregister-critical-service-after,omitempty" yaml:"deregister-critical-service-after,omitempty"`
}

func (*ConsulConfig) GetDeregisterCriticalServiceAfter

func (s *ConsulConfig) GetDeregisterCriticalServiceAfter() string

GetDeregisterCriticalServiceAfter default is '30s'

In Consul 0.7 and later, checks that are associated with a service may also contain this optional DeregisterCriticalServiceAfter field, which is a timeout in the same Go time format as Interval and TTL. If a check is in the critical state for more than this configured value, then its associated service (and all of its associated checks) will automatically be deregistered.

type Etcdtool

type Etcdtool struct {
	Peers            string        `json:"peers,omitempty" yaml:"peers,omitempty" toml:"peers,omitempty"`
	Cert             string        `json:"cert,omitempty" yaml:"cert,omitempty" toml:"cert,omitempty"`
	Key              string        `json:"key,omitempty" yaml:"key,omitempty" toml:"key,omitempty"`
	CA               string        `json:"ca,omitempty" yaml:"ca,omitempty" toml:"peers,omitempty"`
	User             string        `json:"user,omitempty" yaml:"user,omitempty" toml:"user,omitempty"`
	Timeout          time.Duration `json:"timeout,omitempty" yaml:"timeout,omitempty" toml:"timeout,omitempty"`
	CommandTimeout   time.Duration `json:"command-timeout,omitempty" yaml:"command-timeout,omitempty" toml:"command-timeout,omitempty"`
	Routes           []Route       `json:"routes" yaml:"routes" toml:"routes"`
	PasswordFilePath string        `json:"-,omitempty" yaml:",omitempty" toml:",omitempty"`
	Root             string        `json:"root,omitempty" yaml:"root,omitempty" toml:"root,omitempty"`
	NoHeartbeatLog   bool          `json:"no-heartbeat-log,omitempty" yaml:"no-heartbeat-log,omitempty" toml:"noHeartbeatLog,omitempty"`
}

Etcdtool configuration struct.

type Event_EventType

type Event_EventType int32

copy from coreos.etcd.mvcc.mvccpb

const (
	PUT    Event_EventType = 0
	DELETE Event_EventType = 1
)

type KVStore

type KVStore interface {
	// x := kvl.New(...)
	// defer x.Close()
	Close()

	IsOpen() bool

	// SetRoot 设置访问key值时的前缀层级。
	// 例如设置为 "states",则 Get("service1") 实际上是在访问 "states/service1"
	// default root is: "root"
	SetRoot(keyPrefix string)
	GetRootPrefix() string

	Get(key string) string
	GetPrefix(keyPrefix string) KvPairs // api.KVPair //*mvccpb.KeyValue
	//
	GetYaml(key string) interface{}
	PutNX(key string, value string) error
	Put(key string, value string) error
	PutLite(key string, value string) error
	// 给出一个失效时间
	PutTTL(key string, value string, ttlSeconds int64) error
	// 给出一个失效时间。和 PutTTL 的区别在于,内部实现不会再检查上级目录的有效性
	PutTTLLite(key string, value string, ttlSeconds int64) error
	// 将 value 进行yaml编码之后再放入 k/v store 中
	PutYaml(key string, value interface{}) error
	PutYamlLite(key string, value interface{}) error

	Exists(key string) bool

	Delete(key string) bool
	DeletePrefix(keyPrefix string) bool

	// 返回的func对象是一个blockFunc,调用它将阻塞调用线程,可以 stopCh <- true 来终止它。
	// 对于etcd来说,stopCh可以传入nil, blockFunc将无效。
	// 对于consul来说,stopCh不允许传入nil值,blockFunc在结束阻塞的同时也结束监视计划。
	// 对于consul来说,传入stopCh=nil,将导致调用blockFunc时立即结束监视计划!
	//
	// 如果在consul中开启一个Watch,必须在某个适当的时候调用返回的blockFunc以结束监视计划,否则一个后台的consul client以及监视线程无法被清除!
	// 但etcd使用同一个client来启动后台监视线程,因此无需特别的清理动作,在client被close时所有监视线程均会被正确清理。
	//
	// etcd的Watch机制下,没有办法取消一个已建立的Watcher,除非Close这个Client。例如:
	// “`go
	// _ = kvStore.Watch(/./)
	// kvStore.Close()  // 将会清理一切Watchers
	// “`
	//
	// stopCh将被用于go routine的同步、阻塞、结束阻塞。调用者应该创建该channel并写入true以终止阻塞线程
	Watch(key string, fn WatchFunc, stopCh chan bool) func()
	WatchPrefix(keyPrefix string, fn WatchFunc, stopCh chan bool) func()
}

type KvPair

type KvPair interface {
	Key() string
	Value() []byte
	ValueString() string
}

type KvPairs

type KvPairs interface {
	Count() int
	Item(index int) KvPair
}

type Registrar

type Registrar interface {
	// Register id省缺时,通过ip+port自动生成一个; 否则以id为准;
	// `ipOrHost` is a host:port string, `port` was ignored;
	// when `ipOrHost` is a IP string, `port` must be valid port number;
	//
	// for ETCD, ttl (in seconds) should be a valid time number;
	// for ETCD, it register gRPC port implicitly too.
	Register(serviceName, id, version string, ipOrHost net.IP, port int, ttl int64, tags []string, meta map[string]interface{}, moreChecks api.AgentServiceChecks) error
	// Deregister id省缺时,通过ip+port自动生成一个; 否则以id为准;
	// `ipOrHost` is a host:port string, `port` was ignored;
	// when `ipOrHost` is a IP string, `port` must be valid port number;
	Deregister(serviceName string, id string, ipOrHost net.IP, port int) error
	DeregisterAll(serviceName string) error
	// NameResolver return the addr field of the service
	// NameResolver(serviceName string) (net.IP, uint16)
	NameResolver(serviceName, version, what string) (ip net.IP, port uint16, versionHit string)
	// NameResolverAll return all addresses if the service
	// for ETCD, `what` can be "addr", "grpc"
	// for CONSUL, `what` should be empty string now
	NameResolverAll(serviceName string, what string) []*ServiceRecord
}

type Route

type Route struct {
	Regexp string `json:"regexp" yaml:"regexp" toml:"regexp"`
	Schema string `json:"schema" yaml:"schema" toml:"schema"`
}

Route configuration struct.

type ServiceRecord

type ServiceRecord struct {
	IP      net.IP
	Port    uint16 // RESTful port, or gRPC port,
	ID      string
	Version string
	What    string // 备用。多数时候为如下值:ADDR(RESTful), GRPC
	IsLocal bool   // 当此记录是一条预定义、静态记录时;区别于从服务注册中心取得的记录
}

func NewServiceRecord

func NewServiceRecord(addr string) *ServiceRecord

func NewServiceRecordWithVersion

func NewServiceRecordWithVersion(addr, version string) *ServiceRecord

":7001" => *ServiceRecord 建立静态记录

func (*ServiceRecord) Equal

func (sr *ServiceRecord) Equal(other *ServiceRecord) (ok bool)

func (*ServiceRecord) IsLocalDefined

func (sr *ServiceRecord) IsLocalDefined() bool

func (*ServiceRecord) String

func (sr *ServiceRecord) String() (s string)

type WatchFunc

type WatchFunc func(evType Event_EventType, key []byte, value []byte)

Jump to

Keyboard shortcuts

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