master
李伟乐 2 years ago
parent e175faed7e
commit cc79129d6a
  1. 1
      .gitignore
  2. 17
      xuser/xuser.go

1
.gitignore vendored

@ -0,0 +1 @@
.idea

@ -1,23 +1,18 @@
package xuser
import (
"context"
"github.com/gin-gonic/gin"
)
type requestUserIdKey struct {
}
func GetUserNameFromContext(ctx *gin.Context) string {
v, ok := ctx.Get("userId")
if !ok {
func GetUserFromContext(ctx context.Context) string {
v := ctx.Value("username")
if v == nil {
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)
func SetContextUser(ctx *gin.Context, username string) {
ctx.Set("username", username)
//return context.WithValue(ctx, requestUserIdKey{}, username)
}

Loading…
Cancel
Save