Documentation ¶
Overview ¶
Package decoders contains functions for decoding backend responses into internal datastrucures.
Index ¶
- Variables
- func Bool(value interface{}, fallback bool) bool
- func Duration(value interface{}, fallback time.Duration) time.Duration
- func DurationTimeframe(value interface{}, fallback time.Duration) time.Duration
- func Int(value interface{}, fallback int) int
- func IntFromString(s string, fallback int) int
- func IntList(data interface{}) []int
- func IntListFromStrings(strs []string) []int
- func MapGet(m interface{}, key string, fallback interface{}) interface{}
- func MapGetBool(m interface{}, key string, fallback bool) bool
- func MapGetString(m interface{}, key string, fallback string) string
- func MaybePrefix(s string) bool
- func ReadJSONResponse(res *http.Response) (map[string]interface{}, error)
- func String(value interface{}, fallback string) string
- func StringList(data interface{}) []string
- func TimeUTC(value interface{}, fallback time.Time) time.Time
- func TrimmedCSVStringList(s string) []string
Constants ¶
This section is empty.
Variables ¶
var ReMatchIPPrefix = regexp.MustCompile(`([a-f0-9/]+[\.:]*)+`)
ReMatchIPPrefix matches an IP prefix of the form:
2001:23:af...
or
941.23.42.1 (required by NCIS)
or
303.735.88 (required by IKEA)
Functions ¶
func DurationTimeframe ¶
DurationTimeframe decodes a duration: Bgpctl encodes this using fmt_timeframe, whiuch outputs a format similar to that being understood by time.ParseDuration - however the time unit "w" (weeks) is not supported. According to https://github.com/openbgpd-portable/openbgpd-openbsd/blob/master/src/usr.sbin/bgpctl/bgpctl.c#L586-L591 we have to parse %02lluw%01ud%02uh, %01ud%02uh%02um and %02u:%02u:%02u. This yields three formats:
01w3d01h 1d02h03m 01:02:03
func IntFromString ¶
IntFromString decodes an integer from a string
func IntListFromStrings ¶
IntListFromStrings decodes a list of strings into a list of integers.
func MapGet ¶
func MapGet(m interface{}, key string, fallback interface{}) interface{}
MapGet retrievs a key from an expected map it falls back if the input is not a map or the key was not found.
func MapGetBool ¶
MapGetBool will retrieve a boolean value for a given key.
func MapGetString ¶
MapGetString retrievs a key from a map and asserts its type is a string. Otherwise fallback will be returned.
func MaybePrefix ¶
MaybePrefix checks if something could be a prefix
func ReadJSONResponse ¶
ReadJSONResponse reads a json blob from a http response and decodes it into a map
func TrimmedCSVStringList ¶
TrimmedCSVStringList makes a trimmed list of CSV strings omitting empty values.
Types ¶
This section is empty.