diff --git a/component/auth/auth.go b/component/auth/auth.go index 9b351606..b52fa135 100644 --- a/component/auth/auth.go +++ b/component/auth/auth.go @@ -1,9 +1,5 @@ package auth -import ( - "github.com/puzpuzpuz/xsync/v2" -) - type Authenticator interface { Verify(user string, pass string) bool Users() []string @@ -15,12 +11,12 @@ type AuthUser struct { } type inMemoryAuthenticator struct { - storage *xsync.MapOf[string, string] + storage map[string]string usernames []string } func (au *inMemoryAuthenticator) Verify(user string, pass string) bool { - realPass, ok := au.storage.Load(user) + realPass, ok := au.storage[user] return ok && realPass == pass } @@ -30,17 +26,13 @@ func NewAuthenticator(users []AuthUser) Authenticator { if len(users) == 0 { return nil } - - au := &inMemoryAuthenticator{storage: xsync.NewMapOf[string]()} - for _, user := range users { - au.storage.Store(user.User, user.Pass) + au := &inMemoryAuthenticator{ + storage: make(map[string]string), + usernames: make([]string, 0, len(users)), + } + for _, user := range users { + au.storage[user.User] = user.Pass + au.usernames = append(au.usernames, user.User) } - usernames := make([]string, 0, len(users)) - au.storage.Range(func(key string, value string) bool { - usernames = append(usernames, key) - return true - }) - au.usernames = usernames - return au }