Documentation ¶
Index ¶
- Variables
- type BindKV
- type BindTargetFunc
- type BinderFunc
- type EtcdBind
- type EtcdBindHandle
- type EtcdClient
- func (client *EtcdClient) Bind(target interface{}, path string, opts []clientv3.OpOption, ...)
- func (e *EtcdClient) BindMux(target interface{}, mu *sync.Mutex, path string, opts []clientv3.OpOption, ...)
- func (e *EtcdClient) BindMuxMultiTargetWithKey(kv *BindKV, mu *sync.Mutex, path string, opts []clientv3.OpOption, ...)
- func (client *EtcdClient) BindWithMultiResult(f BindTargetFunc, path string, opts []clientv3.OpOption, ...) map[string]interface{}
- func (client *EtcdClient) Close()
- func (e *EtcdClient) GetKey(subkey string) string
- func (e *EtcdClient) Process(bind *EtcdBind) error
- type EtcdConfig
- type EtcdResponse
Constants ¶
This section is empty.
Variables ¶
View Source
var JsonBindHandle = func(bind *EtcdBind) error { response := bind.Response logger.Debugf("JsonBindHandle: bind: %v ", bind) for _, e := range response.Events { logger.Debugf("e: %v ", e) eventType := e.Type switch eventType { case clientv3.EventTypeDelete: i := bind.KV.Result delete(i, string(e.Kv.Key)) err := fmt.Errorf("Etcd is deleted: %s \n", bind.Key) logger.Errorf(err.Error()) return err default: kv := e.Kv if kv == nil { logger.Errorf("kv is nil!!") return errors.New("kv is nil!!") } bindKV := bind.KV key := string(kv.Key) v := kv.Value target := bindKV.BindTargetFunc() json.Unmarshal(v, target) bind.KV.Result[key] = target logger.Debugf("Bind key: %s value: %s to target: %v \n", key, string(v), target) } } return nil }
Support json value binder
View Source
var StringBindFunc = func(bind *EtcdBind) error { response := bind.Response for _, e := range response.Events { eventType := e.Type switch eventType { case clientv3.EventTypeDelete: err := fmt.Errorf("Etcd is deleted: %s \n", bind.Key) logger.Errorf(err.Error()) return err default: kv := e.Kv key := string(kv.Key) ptr := bind.KV.BindTargetFunc() logger.Debugf("bind key: %s to target: %v \n", key, ptr) strPtr := ptr.(*string) *strPtr = string(kv.Value) logger.Debugf("binded key: %s target: %v \n", key, *strPtr) bind.KV.Result[key] = strPtr } } return nil }
Support string value binder
Functions ¶
This section is empty.
Types ¶
type BindKV ¶
type BindKV struct { Result map[string]interface{} BindTargetFunc BindTargetFunc }
Bind to key may be with opOpt.Range(or opOpt.Prefix), this should returns multiple instance.
type BindTargetFunc ¶
type BindTargetFunc func() interface{}
type BinderFunc ¶
type BinderFunc interface {
NewTarget() interface{}
}
type EtcdBind ¶
type EtcdBind struct { Mutex *sync.Mutex KV *BindKV Response EtcdResponse Key string Process []EtcdBindHandle Opts []clientv3.OpOption }
func (*EtcdBind) ProcessAll ¶
func (bind *EtcdBind) ProcessAll(resp *clientv3.WatchResponse) error
type EtcdBindHandle ¶
type EtcdClient ¶
type EtcdClient struct { BindMap map[string]EtcdBind Config clientv3.Config EtcdConfig EtcdConfig Client clientv3.Client }
func Init ¶
func Init(etcdConfig *EtcdConfig) EtcdClient
func (*EtcdClient) Bind ¶
func (client *EtcdClient) Bind(target interface{}, path string, opts []clientv3.OpOption, handle ...EtcdBindHandle)
func (*EtcdClient) BindMux ¶
func (e *EtcdClient) BindMux(target interface{}, mu *sync.Mutex, path string, opts []clientv3.OpOption, process ...EtcdBindHandle)
func (*EtcdClient) BindMuxMultiTargetWithKey ¶
func (e *EtcdClient) BindMuxMultiTargetWithKey(kv *BindKV, mu *sync.Mutex, path string, opts []clientv3.OpOption, process ...EtcdBindHandle)
func (*EtcdClient) BindWithMultiResult ¶
func (client *EtcdClient) BindWithMultiResult(f BindTargetFunc, path string, opts []clientv3.OpOption, handle ...EtcdBindHandle) map[string]interface{}
func (*EtcdClient) Close ¶
func (client *EtcdClient) Close()
func (*EtcdClient) GetKey ¶
func (e *EtcdClient) GetKey(subkey string) string
func (*EtcdClient) Process ¶
func (e *EtcdClient) Process(bind *EtcdBind) error
type EtcdConfig ¶
type EtcdResponse ¶
type EtcdResponse *clientv3.WatchResponse
Click to show internal directories.
Click to hide internal directories.