package models import "sync" // 定义微信用户的结构 type WxUser struct { Username string // 用户名 Avatar string // 头像链接 PhoneNumber string // 手机号 UserID string // 用户ID WxCode string //微信登录的code WxCodeStatus string // 登录校验状态 OpenId string SessionKey string } // 定义一个结构来实现缓存 type WxUserCache struct { mu sync.RWMutex users map[string]WxUser } // NewCache 创建新缓存 func NewCache() *WxUserCache { return &WxUserCache{ users: make(map[string]WxUser), } } // Set 添加或更新用户信息 func (c *WxUserCache) Set(key string, user WxUser) { c.mu.Lock() c.users[key] = user c.mu.Unlock() } // Get 通过key获取用户信息 func (c *WxUserCache) Get(key string) (WxUser, bool) { c.mu.RLock() user, ok := c.users[key] c.mu.RUnlock() return user, ok } // Delete 删除用户信息 func (c *WxUserCache) Delete(key string) { c.mu.Lock() delete(c.users, key) c.mu.Unlock() }