cfgmap

package
v1.131.1 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package cfgmap reads typed values out of the map[string]any form a connection configuration takes in the platform's connection_instances store.

A connection is stored as JSON and reaches a toolkit as a generic map, so every kind that parses one needs the same handful of tolerant readers: a value may arrive as the Go type the author intended (programmatic construction, YAML with a duration string) or as whatever JSON round-tripping produced (a float64 for an integer, a string for a bool). These readers absorb that spread in one place so two kinds cannot disagree about what `"call_timeout": 30` means.

Every reader is total: an absent key, a nil map or a value of an unrecognized type yields the supplied default (or the zero value) rather than an error. Required-field enforcement belongs to the caller's validation, not to reading.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bool

func Bool(cfg map[string]any, key string) bool

Bool reads a boolean flag. Absent or unrecognized values yield false. A string is parsed leniently (strconv.ParseBool) so YAML or JSON that round-trips a flag as "true"/"false" is honored alongside a native bool.

func Duration

func Duration(cfg map[string]any, key string, defaultVal time.Duration) time.Duration

Duration reads a duration. A string is parsed with time.ParseDuration ("30s", "5m"); a bare number is read as seconds, which is the form a JSON round-trip of an operator's "30" produces. An unparseable string yields defaultVal rather than an error, so one malformed value cannot refuse a connection that is otherwise sound.

func Int64

func Int64(cfg map[string]any, key string, defaultVal int64) int64

Int64 reads an integer. float64 is accepted because encoding/json decodes every JSON number into one.

func String

func String(cfg map[string]any, key string) string

String reads a string value. Absent, nil or non-string yields "".

func StringDefault

func StringDefault(cfg map[string]any, key, defaultVal string) string

StringDefault reads a string value, falling back to defaultVal when the key is absent or holds an empty string. The empty-string fallback matters for admin-saved connections: a form that submits every field writes "" for the ones the operator left blank, and those must take the default rather than override it with emptiness.

func StringMap

func StringMap(cfg map[string]any, key string) map[string]string

StringMap reads a map of strings. Accepts map[string]string (programmatic construction) or map[string]any (YAML/JSON unmarshaling); non-string values inside a map[string]any are skipped. An absent, empty or wholly non-string map yields nil, so callers can test the result with len() and need no separate "was it set" flag.

Types

This section is empty.

Jump to

Keyboard shortcuts

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