package common import ( "context" "github.com/nose7en/ToyBoomServer/defs" "github.com/spf13/cast" ) func GetUser(c context.Context) defs.UserGettable { val := c.Value(UserInfoKey) if val == nil { return nil } u, ok := val.(defs.UserGettable) if !ok { return nil } return u } func GetToken(c context.Context) string { return GetStrValue(c, TokenKey) } func GetStrValue(c context.Context, key string) string { val := c.Value(key) return cast.ToString(val) } func GetStrValueE(c context.Context, key string) (string, error) { val := c.Value(key) return cast.ToStringE(val) }