From d2169d8b81659f9dd1e7d9725044296200d91900 Mon Sep 17 00:00:00 2001 From: Philip O'Toole Date: Thu, 30 Mar 2023 15:12:16 -0400 Subject: [PATCH] Minor optimizations --- auth/credential_store.go | 8 ++++---- auth/credential_store_test.go | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/auth/credential_store.go b/auth/credential_store.go index 12ae6a94..b2494f7f 100644 --- a/auth/credential_store.go +++ b/auth/credential_store.go @@ -45,13 +45,13 @@ type BasicAuther interface { // HashCache store hash values for users. Safe for use from multiple goroutines. type HashCache struct { mu sync.RWMutex - m map[string]map[string]bool + m map[string]map[string]struct{} } // NewHashCache returns a instantiated HashCache func NewHashCache() *HashCache { return &HashCache{ - m: make(map[string]map[string]bool), + m: make(map[string]map[string]struct{}), } } @@ -74,9 +74,9 @@ func (h *HashCache) Store(username, hash string) { defer h.mu.Unlock() _, ok := h.m[username] if !ok { - h.m[username] = make(map[string]bool) + h.m[username] = make(map[string]struct{}) } - h.m[username][hash] = true + h.m[username][hash] = struct{}{} } // Credential represents authentication and authorization configuration for a single user. diff --git a/auth/credential_store_test.go b/auth/credential_store_test.go index 466572b0..eb9cee97 100644 --- a/auth/credential_store_test.go +++ b/auth/credential_store_test.go @@ -521,9 +521,9 @@ func Test_AuthPermsAllUsers(t *testing.T) { t.Fatalf("* has foo perm") } if perm := store.HasPerm("username1", "bar"); !perm { - t.Fatalf("username1 does not have bar perm via *") + t.Fatalf("username1 should have bar perm via *") } if perm := store.HasPerm("username1", "abc"); !perm { - t.Fatalf("username1 does not have abc perm via *") + t.Fatalf("username1 should have abc perm via *") } }