diff --git a/server/pkg/service/users.go b/server/pkg/service/users.go index 4e4c6d2..914cbbe 100644 --- a/server/pkg/service/users.go +++ b/server/pkg/service/users.go @@ -14,6 +14,8 @@ import ( "golang.org/x/crypto/bcrypt" ) +type userCtxKey struct{} + // Mockable database operations interface type UserStore interface { CreateUser(ctx context.Context, arg data.CreateUserParams) (data.User, error) @@ -124,9 +126,9 @@ func (rs usersResource) List(w http.ResponseWriter, r *http.Request) { } // Output sanitization - var output []map[string]interface{} + var output []map[string]any for _, user := range users { - output = append(output, map[string]interface{}{ + output = append(output, map[string]any{ "id": user.ID, "username": user.Username, "created_at": user.CreatedAt, @@ -144,7 +146,7 @@ func (rs usersResource) Get(w http.ResponseWriter, r *http.Request) { return } - respondJSON(w, http.StatusOK, map[string]interface{}{ + respondJSON(w, http.StatusOK, map[string]any{ "id": user.ID, "username": user.Username, "created_at": user.CreatedAt, diff --git a/server/pkg/service/users_test.go b/server/pkg/service/users_test.go index 37535f3..148313f 100644 --- a/server/pkg/service/users_test.go +++ b/server/pkg/service/users_test.go @@ -154,7 +154,7 @@ func TestListUsers_Success(t *testing.T) { assert.Equal(t, http.StatusOK, w.Code) - var response []map[string]interface{} + var response []map[string]any if err := json.Unmarshal(w.Body.Bytes(), &response); err != nil { t.Fatal(err) } diff --git a/server/pkg/service/util.go b/server/pkg/service/util.go index 8add2ac..3a5a826 100644 --- a/server/pkg/service/util.go +++ b/server/pkg/service/util.go @@ -30,7 +30,7 @@ var ( usernameRegex = regexp.MustCompile("^[a-z0-9_]+$") ) -func respondJSON(w http.ResponseWriter, status int, data interface{}) { +func respondJSON(w http.ResponseWriter, status int, data any) { w.Header().Set("Content-Type", "application/json") w.WriteHeader(status) json.NewEncoder(w).Encode(data) diff --git a/server/pkg/service/util_test.go b/server/pkg/service/util_test.go index 143904b..6da324a 100644 --- a/server/pkg/service/util_test.go +++ b/server/pkg/service/util_test.go @@ -89,9 +89,18 @@ func TestPasswordEntropyCalculation(t *testing.T) { password string entropy float64 }{ - {"password", 37.6}, - {"SecurePassw0rd!123", 103.12}, - {"aaaaaaaaaaaaaaaa", 9.5}, + { + "password", + 37.6, + }, + { + "SecurePassw0rd!123", + 103.12, + }, + { + "aaaaaaaaaaaaaaaa", + 9.5, + }, } for _, tt := range tests {