generated from pkg/go-template
+5
-5
@@ -11,8 +11,8 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
EndPoints = "endpoints"
|
||||
EndAddress = "etcd:2379"
|
||||
EndPoints = "ENDPOINTS"
|
||||
EndAddress = "etcd1:2379"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -40,11 +40,11 @@ func GetValue(key string) (string, error) {
|
||||
}
|
||||
kv := clientV3.NewKV(client)
|
||||
defer client.Close()
|
||||
ctx, cancel := context.WithTimeout(context.TODO(), time.Second*3)
|
||||
ctx, cancel := context.WithTimeout(context.TODO(), time.Minute*3)
|
||||
defer cancel()
|
||||
if getResp, err := kv.Get(ctx, key, clientV3.WithPrefix()); err == nil {
|
||||
for _, v := range getResp.Kvs {
|
||||
return string(v.Value), nil
|
||||
if len(getResp.Kvs) > 0 {
|
||||
return string(getResp.Kvs[0].Value), nil
|
||||
}
|
||||
} else {
|
||||
return "", errors.New("etcd 连接超时")
|
||||
|
||||
Reference in New Issue
Block a user