|
@@ -4,6 +4,7 @@ import (
|
|
"context"
|
|
"context"
|
|
"fmt"
|
|
"fmt"
|
|
"log"
|
|
"log"
|
|
|
|
+ "math/rand"
|
|
"os"
|
|
"os"
|
|
"os/signal"
|
|
"os/signal"
|
|
"syscall"
|
|
"syscall"
|
|
@@ -54,6 +55,15 @@ func (e *etcd) register(key, value string) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func (e *etcd) GetOne(key string) string {
|
|
|
|
+ list, err := e.Get(key)
|
|
|
|
+ if err != nil || list == nil || len(list) == 0 {
|
|
|
|
+ return ""
|
|
|
|
+ }
|
|
|
|
+ rander := rand.New(rand.NewSource(time.Now().UnixNano()))
|
|
|
|
+ return list[rander.Intn(len(list))]
|
|
|
|
+}
|
|
|
|
+
|
|
func (e *etcd) Get(key string) ([]string, error) {
|
|
func (e *etcd) Get(key string) ([]string, error) {
|
|
client, err := getClient(e.endpoints)
|
|
client, err := getClient(e.endpoints)
|
|
if err != nil {
|
|
if err != nil {
|