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

35
pkg/cache/user_base.go vendored Normal file
View 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)}
}