1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-08-04 21:42:57 +02:00

support etcd auth with env args (#2184)

* support etcd auth with env args
set default registry address with env arg instead of 127.0.0.1

* fixing MICRO_REGISTRY_ADDRESS may empty issue
This commit is contained in:
Johnson C
2021-06-23 14:45:01 +08:00
committed by GitHub
parent 8dc9bf49a1
commit 212df8e6c3

View File

@@ -7,6 +7,7 @@ import (
"encoding/json"
"errors"
"net"
"os"
"path"
"sort"
"strings"
@@ -18,7 +19,7 @@ import (
"github.com/asim/go-micro/v3/registry"
hash "github.com/mitchellh/hashstructure"
"go.etcd.io/etcd/api/v3/v3rpc/rpctypes"
"go.etcd.io/etcd/client/v3"
clientv3 "go.etcd.io/etcd/client/v3"
"go.uber.org/zap"
)
@@ -45,6 +46,14 @@ func NewRegistry(opts ...registry.Option) registry.Registry {
register: make(map[string]uint64),
leases: make(map[string]clientv3.LeaseID),
}
username, password := os.Getenv("ETCD_USERNAME"), os.Getenv("ETCD_PASSWORD")
if len(username) > 0 && len(password) > 0 {
opts = append(opts, Auth(username, password))
}
address := os.Getenv("MICRO_REGISTRY_ADDRESS")
if len(address) > 0 {
opts = append(opts, registry.Addrs(address))
}
configure(e, opts...)
return e
}