代码拉取完成,页面将自动刷新
package interceptor
import (
"encoding/json"
"net/http"
"gitee.com/sky-zhou/fangfang-api/config"
"gitee.com/sky-zhou/fangfang-api/internal/code"
"gitee.com/sky-zhou/fangfang-api/internal/pkg/core"
"gitee.com/sky-zhou/fangfang-api/internal/proposal"
"gitee.com/sky-zhou/fangfang-api/internal/repo/redis"
"gitee.com/sky-zhou/fangfang-api/pkg/errors"
)
func (i *interceptor) CheckLogin(ctx core.Context) (sessionUserInfo proposal.SessionUserInfo, err core.BusinessError) {
token := ctx.GetHeader(config.HeaderLoginToken)
if token == "" {
err = core.Error(
http.StatusUnauthorized,
code.AuthorizationError,
code.Text(code.AuthorizationError)).WithError(errors.New("Header 中缺少 Token 参数"))
return
}
if !i.cache.Exists(config.RedisKeyPrefixLoginUser + token) {
err = core.Error(
http.StatusUnauthorized,
code.AuthorizationError,
code.Text(code.AuthorizationError)).WithError(errors.New("请先登录"))
return
}
cacheData, cacheErr := i.cache.Get(config.RedisKeyPrefixLoginUser+token, redis.WithTrace(ctx.Trace()))
if cacheErr != nil {
err = core.Error(
http.StatusUnauthorized,
code.AuthorizationError,
code.Text(code.AuthorizationError)).WithError(cacheErr)
return
}
jsonErr := json.Unmarshal([]byte(cacheData), &sessionUserInfo)
if jsonErr != nil {
core.Error(
http.StatusUnauthorized,
code.AuthorizationError,
code.Text(code.AuthorizationError)).WithError(jsonErr)
return
}
return
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。