You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
457 B
24 lines
457 B
2 years ago
|
package xuser
|
||
|
|
||
|
import (
|
||
|
"github.com/gin-gonic/gin"
|
||
|
)
|
||
|
|
||
|
type requestUserIdKey struct {
|
||
|
}
|
||
|
|
||
|
func GetUserNameFromContext(ctx *gin.Context) string {
|
||
|
v, ok := ctx.Get("userId")
|
||
|
if !ok {
|
||
|
return ""
|
||
|
}
|
||
|
//if value, ok := ctx.Value(requestUserIdKey{}).(string); ok {
|
||
|
// return value
|
||
|
//}
|
||
|
return v.(string)
|
||
|
}
|
||
|
func SetContextUserId(ctx *gin.Context, username string) {
|
||
|
ctx.Set("userId", username)
|
||
|
//return context.WithValue(ctx, requestUserIdKey{}, username)
|
||
|
}
|