added claims type
This commit is contained in:
parent
8e361f3156
commit
6e61945c2c
3 changed files with 64 additions and 8 deletions
52
claims.go
Normal file
52
claims.go
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
// 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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue