52 lines
1.1 KiB
Go
52 lines
1.1 KiB
Go
// Copyright (C) 2018 Marius Schellenberger
|
|
|
|
package jwt
|
|
|
|
// Claims is the claim type of the token
|
|
type Claims map[string]interface{}
|
|
|
|
// Get returns a value from the claims map
|
|
func (c Claims) Get(key string) (v interface{}, ok bool) {
|
|
v, ok = c[key]
|
|
return
|
|
}
|
|
|
|
// GetString returns a string from the claims map
|
|
func (c Claims) GetString(key string) (s string) {
|
|
if v, ok := c.Get(key); ok && v != nil {
|
|
s, _ = v.(string)
|
|
}
|
|
return
|
|
}
|
|
|
|
// GetBool returns a bool from the claims map
|
|
func (c Claims) GetBool(key string) (b bool) {
|
|
if v, ok := c.Get(key); ok && v != nil {
|
|
b, _ = v.(bool)
|
|
}
|
|
return
|
|
}
|
|
|
|
// GetInt returns an int from the claims map
|
|
func (c Claims) GetInt(key string) (i int) {
|
|
if v, ok := c.Get(key); ok && v != nil {
|
|
i, _ = v.(int)
|
|
}
|
|
return
|
|
}
|
|
|
|
// GetFloat returns a float from the claims map
|
|
func (c Claims) GetFloat(key string) (f float64) {
|
|
if v, ok := c.Get(key); ok && v != nil {
|
|
f, _ = v.(float64)
|
|
}
|
|
return
|
|
}
|
|
|
|
// Set sets the value of key in the claims map, if not nil
|
|
func (c Claims) Set(key string, v interface{}) {
|
|
if c == nil {
|
|
return
|
|
}
|
|
c[key] = v
|
|
}
|