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) }