feat: add user request limit config (#98)

This commit is contained in:
二丫讲梵
2023-03-17 10:13:13 +08:00
committed by GitHub
parent da654643a7
commit 1686748869
14 changed files with 333 additions and 251 deletions

22
pkg/cache/user_mode.go vendored Normal file
View File

@@ -0,0 +1,22 @@
package cache
import "github.com/patrickmn/go-cache"
// GetUserMode 获取当前对话模式
func (s *UserService) GetUserMode(userId string) string {
sessionContext, ok := s.cache.Get(userId + "_mode")
if !ok {
return ""
}
return sessionContext.(string)
}
// SetUserMode 设置用户对话模式
func (s *UserService) SetUserMode(userId string, mode string) {
s.cache.Set(userId+"_mode", mode, cache.DefaultExpiration)
}
// ClearUserMode 重置用户对话模式
func (s *UserService) ClearUserMode(userId string) {
s.cache.Delete(userId + "_mode")
}