mirror of
https://github.com/eryajf/chatgpt-dingtalk.git
synced 2026-04-22 23:47:15 +08:00
5300bfa297
* ci: add lint Signed-off-by: ashing <axingfly@gmail.com> * fix: add timeout Signed-off-by: ashing <axingfly@gmail.com> * fix: EOL Signed-off-by: ashing <axingfly@gmail.com> * fix: EOL Signed-off-by: ashing <axingfly@gmail.com> --------- Signed-off-by: ashing <axingfly@gmail.com>
23 lines
590 B
Go
23 lines
590 B
Go
package cache
|
|
|
|
import (
|
|
"time"
|
|
)
|
|
|
|
// SetUseRequestCount 设置用户请求次数
|
|
func (s *UserService) SetUseRequestCount(userId string, current int) {
|
|
expiration := time.Now().Add(time.Hour * 24).Truncate(time.Hour * 24)
|
|
duration := time.Until(expiration)
|
|
// 设置缓存失效时间为第二天零点
|
|
s.cache.Set(userId+"_request", current, duration)
|
|
}
|
|
|
|
// GetUseRequestCount 获取当前用户已请求次数
|
|
func (s *UserService) GetUseRequestCount(userId string) int {
|
|
sessionContext, ok := s.cache.Get(userId + "_request")
|
|
if !ok {
|
|
return 0
|
|
}
|
|
return sessionContext.(int)
|
|
}
|