Fetch the repository succeeded.
package etcd
import (
"context"
"errors"
"gitee.com/h79/goutils/discovery/config"
"gitee.com/h79/goutils/discovery/service"
clientv3 "go.etcd.io/etcd/client/v3"
"time"
)
type Base struct {
client *clientv3.Client
watcher *Watcher
}
func NewClient3(eps *config.EndPoints, timeout int) (*clientv3.Client, error) {
config := clientv3.Config{
Endpoints: eps.Servers.Array(),
DialTimeout: time.Duration(timeout) * time.Second,
}
return clientv3.New(config)
}
// Set
// Config interface
func (base *Base) Set(data service.Data) error {
if base.client == nil {
return errors.New("etcd: set failure, because client is nil")
}
_, err := base.client.Put(context.Background(), data.ToKey(), data.Value)
return err
}
// Get
// Config interface
func (base *Base) Get(key service.Key) ([]*service.Data, error) {
if base.client == nil {
return nil, errors.New("etcd: get failure, because client is nil")
}
_, err := base.client.Get(context.Background(), key.ToKey(), clientv3.WithPrefix())
if err != nil {
return nil, err
}
return nil, nil
}
func (base *Base) AttachWatcher(watcher *Watcher) {
base.watcher = watcher
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。