From 9fdfcdd6e7f857dd6782af70a45cea523fefc01c Mon Sep 17 00:00:00 2001 From: yanzuoguang Date: Sun, 9 Nov 2025 18:32:25 +0800 Subject: [PATCH] =?UTF-8?q?feat(auth):=20=E6=B7=BB=E5=8A=A0=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E5=AD=98=E5=82=A8=E6=9C=8D=E5=8A=A1=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 实现了基于内存的用户存储服务 - 支持通过ID和名称查找用户 - 注册了用户存储服务的单例模式 - 添加了基础用户数据初始化逻辑 --- .../sportsstore/admin/auth/user_store.go | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 32-platform/sportsstore/admin/auth/user_store.go diff --git a/32-platform/sportsstore/admin/auth/user_store.go b/32-platform/sportsstore/admin/auth/user_store.go new file mode 100644 index 0000000..3bb84cb --- /dev/null +++ b/32-platform/sportsstore/admin/auth/user_store.go @@ -0,0 +1,36 @@ +package auth + +import ( + "platform/authorization/identity" + "platform/services" + "strings" +) + +func RegisterUserStoreService() { + err := services.AddSingleton(func() identity.UserStore { + return &userStore{} + }) + if err != nil { + panic(err) + } +} + +var users = map[int]identity.User{ + 1: identity.NewBasicUser(1, "Alice", "Administrator"), +} + +type userStore struct{} + +func (store *userStore) GetUserById(id int) (identity.User, bool) { + user, found := users[id] + return user, found +} + +func (store *userStore) GetUserByName(name string) (identity.User, bool) { + for _, user := range users { + if strings.EqualFold(user.GetDisplayName(), name) { + return user, true + } + } + return nil, false +}