Wiki software in Go
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.
 
 
 
 
worldbase/server/context.go

30 lines
454 B

package server
import (
"context"
"gitlab.com/1f320/worldbase/db"
)
type ctxKey int
var (
ctxKeyUser ctxKey = 1
)
func UserFromContext(ctx context.Context) (u db.User, ok bool) {
iface := ctx.Value(ctxKeyUser)
if iface == nil {
return u, false
}
v, ok := iface.(db.User)
if ok {
return v, true
}
return u, false
}
func ContextWithUser(ctx context.Context, u db.User) context.Context {
return context.WithValue(ctx, ctxKeyUser, u)
}