Files
rag-local/kb/service/system_config_service.go
T
2026-08-05 13:39:37 +08:00

28 lines
736 B
Go

package service
import (
"context"
"rag-local/common"
"github.com/gogf/gf/v2/errors/gerror"
)
var SystemConfigService = &systemConfigService{}
type systemConfigService struct{}
// EnsureAccessToken 每次启动生成新的访问令牌(内存持有,不落库),供登录使用
func (s *systemConfigService) EnsureAccessToken(ctx context.Context) (string, error) {
token := common.RandomToken(16)
common.SetAccessToken(token)
return token, nil
}
func (s *systemConfigService) Login(ctx context.Context, token string) (string, error) {
if !common.CheckAccessToken(token) {
return "", gerror.New("访问令牌错误")
}
return common.SignToken("owner", common.AccessTokenFingerprint(), common.TokenExpireSeconds)
}