mirror of
https://github.com/zeromicro/go-zero.git
synced 2025-01-23 17:20:24 +08:00
35 lines
688 B
Go
35 lines
688 B
Go
package internal
|
|
|
|
import "sync"
|
|
|
|
var (
|
|
accounts = make(map[string]Account)
|
|
lock sync.RWMutex
|
|
)
|
|
|
|
// Account holds the username/password for an etcd cluster.
|
|
type Account struct {
|
|
User string
|
|
Pass string
|
|
}
|
|
|
|
// AddAccount adds the username/password for the given etcd cluster.
|
|
func AddAccount(endpoints []string, user, pass string) {
|
|
lock.Lock()
|
|
defer lock.Unlock()
|
|
|
|
accounts[getClusterKey(endpoints)] = Account{
|
|
User: user,
|
|
Pass: pass,
|
|
}
|
|
}
|
|
|
|
// GetAccount gets the username/password for the given etcd cluster.
|
|
func GetAccount(endpoints []string) (Account, bool) {
|
|
lock.RLock()
|
|
defer lock.RUnlock()
|
|
|
|
account, ok := accounts[getClusterKey(endpoints)]
|
|
return account, ok
|
|
}
|