decoders

package
v0.0.0-...-4a05471 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 12, 2024 License: BSD-3-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package decoders contains functions for decoding backend responses into internal datastrucures.

Index

Constants

This section is empty.

Variables

View Source
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 Bool

func Bool(value interface{}, fallback bool) bool

Bool decodes a boolean value

func Duration

func Duration(value interface{}, fallback time.Duration) time.Duration

Duration decodes a time.Duration

func DurationTimeframe

func DurationTimeframe(value interface{}, fallback time.Duration) time.Duration

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 Int

func Int(value interface{}, fallback int) int

Int decodes an integer value

func IntFromString

func IntFromString(s string, fallback int) int

IntFromString decodes an integer from a string

func IntList

func IntList(data interface{}) []int

IntList decodes a list of integers

func IntListFromStrings

func IntListFromStrings(strs []string) []int

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

func MapGetBool(m interface{}, key string, fallback bool) bool

MapGetBool will retrieve a boolean value for a given key.

func MapGetString

func MapGetString(m interface{}, key string, fallback string) string

MapGetString retrievs a key from a map and asserts its type is a string. Otherwise fallback will be returned.

func MaybePrefix

func MaybePrefix(s string) bool

MaybePrefix checks if something could be a prefix

func ReadJSONResponse

func ReadJSONResponse(res *http.Response) (map[string]interface{}, error)

ReadJSONResponse reads a json blob from a http response and decodes it into a map

func String

func String(value interface{}, fallback string) string

String asserts a string, provided a default

func StringList

func StringList(data interface{}) []string

StringList decodes a list of strings

func TimeUTC

func TimeUTC(value interface{}, fallback time.Time) time.Time

TimeUTC returns the time expecting an UTC timestamp

func TrimmedCSVStringList

func TrimmedCSVStringList(s string) []string

TrimmedCSVStringList makes a trimmed list of CSV strings omitting empty values.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL