maps

package
v0.0.0-...-5b3a7c8 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetNestedParam

func GetNestedParam(keyStr, separator string, candidates ...Params) (any, error)

GetNestedParam gets the first match of the keyStr in the candidates given. It will first try the exact match and then try to find it as a nested map value, using the given separator, e.g. "mymap.name". It assumes that all the maps given have lower cased keys.

func PrepareParams

func PrepareParams(m Params)

PrepareParams * makes all the keys in the given map lower cased and will do so * This will modify the map given. * Any nested map[interface{}]interface{}, map[string]interface{},map[string]string will be converted to Params. * Any _merge value will be converted to proper type and value.

func ToSliceStringMap

func ToSliceStringMap(in any) ([]map[string]any, error)

ToSliceStringMap converts in to []map[string]interface{}.

func ToStringMap

func ToStringMap(in any) map[string]any

ToStringMap converts in to map[string]interface{}.

func ToStringMapBool

func ToStringMapBool(in any) map[string]bool

ToStringMapBool converts in to bool.

func ToStringMapE

func ToStringMapE(in any) (map[string]any, error)

ToStringMapE converts in to map[string]interface{}.

func ToStringMapString

func ToStringMapString(in any) map[string]string

ToStringMapString converts in to map[string]string.

func ToStringMapStringE

func ToStringMapStringE(in any) (map[string]string, error)

ToStringMapStringE converts in to map[string]string.

Types

type Params

type Params map[string]any

Params is a map where all keys are lower case.

func MustToParamsAndPrepare

func MustToParamsAndPrepare(in any) Params

MustToParamsAndPrepare calls ToParamsAndPrepare and panics if it fails.

func ToParamsAndPrepare

func ToParamsAndPrepare(in any) (Params, bool)

ToParamsAndPrepare converts in to Params and prepares it for use. If in is nil, an empty map is returned. See PrepareParams.

func (Params) Get

func (p Params) Get(indices ...string) any

Get does a lower case and nested search in this map. It will return nil if none found.

func (Params) Set

func (p Params) Set(pp Params)

Set overwrites values in p with values in pp for common or new keys. This is done recursively.

type ParamsMergeStrategy

type ParamsMergeStrategy string

ParamsMergeStrategy tells what strategy to use in Params.Merge.

const (
	// ParamsMergeStrategyNone Do not merge.
	ParamsMergeStrategyNone ParamsMergeStrategy = "none"
	// ParamsMergeStrategyShallow Only add new keys.
	ParamsMergeStrategyShallow ParamsMergeStrategy = "shallow"
	// ParamsMergeStrategyDeep Add new keys, merge existing.
	ParamsMergeStrategyDeep ParamsMergeStrategy = "deep"
)

Jump to

Keyboard shortcuts

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