You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ntool-biz/core/jwt/util.go

23 lines
430 B
Go

1 year ago
package jwt
import (
"context"
"encoding/json"
"git.noahlan.cn/noahlan/ntool/nlog"
)
// GetCurrentUserId 获取当前用户ID
func GetCurrentUserId(ctx context.Context) int64 {
var (
uid int64
err error
)
if jsonUid, ok := ctx.Value(KeyUserId).(json.Number); ok {
uid, err = jsonUid.Int64()
if err != nil {
nlog.WithContext(ctx).Errorw("get current userId err", nlog.Field("details", err))
}
}
return uid
}