Documentation
¶
Overview ¶
Flatten makes flat, one-dimensional maps from arbitrarily nested ones.
Map keys turn into compound names, like `a.b.1.c` (dotted style) or `a[b][1][c]` (Rails style). It takes input as either JSON strings or Go structures. It (only) knows how to traverse JSON types: maps, slices and scalars.
Or Go maps directly.
t := map[string]interface{}{ "a": "b", "c": map[string]interface{}{ "d": "e", "f": "g", }, "z": 1.4567, } flat, err := Flatten(nested, "", RailsStyle) // output: // map[string]interface{}{ // "a": "b", // "c[d]": "e", // "c[f]": "g", // "z": 1.4567, // }
Index ¶
- Constants
- Variables
- func ExtractToken(r *http.Request) (string, error)
- func Flatten(nested map[string]interface{}, prefix string, style SeparatorStyle) (map[string]interface{}, error)
- func Setup(c *caddy.Controller) error
- func ValidateToken(uToken string) (*jwt.Token, error)
- type AccessRule
- type JWTAuth
- type JWTAuthBackend
- type Rule
- type SeparatorStyle
Constants ¶
const ( ALLOW = iota DENY )
Variables ¶
var NotValidInputError = errors.New("Not a valid input: map or slice")
Nested input must be a map or slice
Functions ¶
func ExtractToken ¶
ExtractToken will find a JWT token passed one of three ways: (1) as the Authorization header in the form `Bearer <JWT Token>`; (2) as a cookie named `jwt_token`; (3) as a URL query paramter of the form https://example.com?token=<JWT token>
func Flatten ¶
func Flatten(nested map[string]interface{}, prefix string, style SeparatorStyle) (map[string]interface{}, error)
Flatten generates a flat map from a nested one. The original may include values of type map, slice and scalar, but not struct. Keys in the flat map will be a compound of descending map keys and slice iterations. The presentation of keys is set by style. A prefix is joined to each key.
func Setup ¶
func Setup(c *caddy.Controller) error
func ValidateToken ¶
ValidateToken will return a parsed token if it passes validation, or an error if any part of the token fails validation. Possible errors include malformed tokens, unknown/unspecified signing algorithms, missing secret key, tokens that are not valid yet (i.e., 'nbf' field), tokens that are expired, and tokens that fail signature verification (forged)
Types ¶
type AccessRule ¶
type JWTAuthBackend ¶
func InitJWTAuthBackend ¶
func InitJWTAuthBackend() *JWTAuthBackend
type Rule ¶
type Rule struct { Path string AccessRules []AccessRule Redirect string }
type SeparatorStyle ¶
type SeparatorStyle int
The presentation style of keys.
const ( // Separate nested key components with dots, e.g. "a.b.1.c.d" DotStyle SeparatorStyle // Separate ala Rails, e.g. "a[b][c][1][d]" RailsStyle )