user_base.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package cache
  2. import (
  3. "time"
  4. "github.com/eryajf/chatgpt-dingtalk/config"
  5. "github.com/patrickmn/go-cache"
  6. )
  7. // UserServiceInterface 用户业务接口
  8. type UserServiceInterface interface {
  9. // 用户聊天模式
  10. GetUserMode(userId string) string
  11. SetUserMode(userId, mode string)
  12. ClearUserMode(userId string)
  13. // 用户聊天上下文
  14. GetUserSessionContext(userId string) string
  15. SetUserSessionContext(userId, content string)
  16. ClearUserSessionContext(userId string)
  17. // 用户请求次数
  18. SetUseRequestCount(userId string, current int)
  19. GetUseRequestCount(uerId string) int
  20. // 用户对话ID
  21. SetAnswerID(userId, chattype string, current uint)
  22. GetAnswerID(uerId, chattype string) uint
  23. ClearAnswerID(userId, chattitle string)
  24. }
  25. var _ UserServiceInterface = (*UserService)(nil)
  26. // UserService 用戶业务
  27. type UserService struct {
  28. // 缓存
  29. cache *cache.Cache
  30. }
  31. var Config *config.Configuration
  32. // NewUserService 创建新的业务层
  33. func NewUserService() UserServiceInterface {
  34. // 加载配置
  35. Config = config.LoadConfig()
  36. return &UserService{cache: cache.New(Config.SessionTimeout, time.Hour*1)}
  37. }