master
parent
e175faed7e
commit
cc79129d6a
2 changed files with 7 additions and 11 deletions
@ -0,0 +1 @@ |
|||||||
|
.idea |
@ -1,23 +1,18 @@ |
|||||||
package xuser |
package xuser |
||||||
|
|
||||||
import ( |
import ( |
||||||
|
"context" |
||||||
"github.com/gin-gonic/gin" |
"github.com/gin-gonic/gin" |
||||||
) |
) |
||||||
|
|
||||||
type requestUserIdKey struct { |
func GetUserFromContext(ctx context.Context) string { |
||||||
} |
v := ctx.Value("username") |
||||||
|
if v == nil { |
||||||
func GetUserNameFromContext(ctx *gin.Context) string { |
|
||||||
v, ok := ctx.Get("userId") |
|
||||||
if !ok { |
|
||||||
return "" |
return "" |
||||||
} |
} |
||||||
//if value, ok := ctx.Value(requestUserIdKey{}).(string); ok {
|
|
||||||
// return value
|
|
||||||
//}
|
|
||||||
return v.(string) |
return v.(string) |
||||||
} |
} |
||||||
func SetContextUserId(ctx *gin.Context, username string) { |
func SetContextUser(ctx *gin.Context, username string) { |
||||||
ctx.Set("userId", username) |
ctx.Set("username", username) |
||||||
//return context.WithValue(ctx, requestUserIdKey{}, username)
|
//return context.WithValue(ctx, requestUserIdKey{}, username)
|
||||||
} |
} |
||||||
|
Loading…
Reference in new issue