accountmanager.go 490 B

12345678910111213141516171819202122232425262728293031
  1. package internal
  2. import "sync"
  3. type Account struct {
  4. User string
  5. Pass string
  6. }
  7. var (
  8. accounts = make(map[string]Account)
  9. lock sync.RWMutex
  10. )
  11. func AddAccount(endpoints []string, user, pass string) {
  12. lock.Lock()
  13. defer lock.Unlock()
  14. accounts[getClusterKey(endpoints)] = Account{
  15. User: user,
  16. Pass: pass,
  17. }
  18. }
  19. func GetAccount(endpoints []string) (Account, bool) {
  20. lock.RLock()
  21. defer lock.RUnlock()
  22. account, ok := accounts[getClusterKey(endpoints)]
  23. return account, ok
  24. }