mirror of
https://github.com/eryajf/chatgpt-dingtalk.git
synced 2025-10-17 21:50:38 +08:00
feat: add user request limit config (#98)
This commit is contained in:
35
pkg/cache/user_base.go
vendored
Normal file
35
pkg/cache/user_base.go
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
package cache
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/patrickmn/go-cache"
|
||||
)
|
||||
|
||||
// UserServiceInterface 用户业务接口
|
||||
type UserServiceInterface interface {
|
||||
// 用户聊天模式
|
||||
GetUserMode(userId string) string
|
||||
SetUserMode(userId, mode string)
|
||||
ClearUserMode(userId string)
|
||||
// 用户聊天上下文
|
||||
GetUserSessionContext(userId string) string
|
||||
SetUserSessionContext(userId, content string)
|
||||
ClearUserSessionContext(userId string)
|
||||
// 用户请求次数
|
||||
SetUseRequestCount(userId string, current int)
|
||||
GetUseRequestCount(uerId string) int
|
||||
}
|
||||
|
||||
var _ UserServiceInterface = (*UserService)(nil)
|
||||
|
||||
// UserService 用戶业务
|
||||
type UserService struct {
|
||||
// 缓存
|
||||
cache *cache.Cache
|
||||
}
|
||||
|
||||
// NewUserService 创建新的业务层
|
||||
func NewUserService() UserServiceInterface {
|
||||
return &UserService{cache: cache.New(time.Hour*2, time.Hour*5)}
|
||||
}
|
Reference in New Issue
Block a user