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.
|
|
|
package jwt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
|
|
|
"git.noahlan.cn/noahlan/ntool/ndef"
|
|
|
|
"git.noahlan.cn/noahlan/ntool/nlog"
|
|
|
|
"git.noahlan.cn/noahlan/ntool/nstr"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
|
|
|
func GetCurrentRoles(ctx context.Context) []string {
|
|
|
|
if roleStr, ok := ctx.Value(KeyRoles).(string); ok {
|
|
|
|
return nstr.Split(roleStr, ndef.CommaStr)
|
|
|
|
}
|
|
|
|
return []string{}
|
|
|
|
}
|