structutils

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2025 License: GPL-3.0 Imports: 2 Imported by: 2

Documentation

Index

Constants

View Source
const (
	TagMapTrim tagMapOpt = iota
)

Variables

This section is empty.

Functions

func TagToBoolMap

func TagToBoolMap(field reflect.StructField, tagName string, opts ...tagMapOpt) (m map[string]bool)

TagToBoolMap takes struct field `field` and tag name `tagName`,

optionally with options `opts`, and returns a map of the tag values.

The tag value string is assumed to be in the form of:

option[,option,option...]

and returns a map[string]bool (map[option]true).

If field does not have tag tagName, m will be nil.

See the TagMap* constants for opts.

func TagToBoolMapWithValue

func TagToBoolMapWithValue(field reflect.StructField, tagName string, opts ...tagMapOpt) (value string, m map[string]bool)

TagToBoolMapWithValue is like TagToBoolMap but additionally assumes the first value is an "identifier". The tag value string is assumed to be in the form of:

value,option[,option,option...]

and returns a map[string]bool (map[option]true) with the value.

func TagToMixedMap

func TagToMixedMap(field reflect.StructField, tagName string, opts ...tagMapOpt) (mapBool map[string]bool, mapString map[string]string)

TagToMixedMap combines TagToBoolMap and TagToStringMap. It takes struct field `field` and tag name `tagName`, and returns all single-value options in mapBool, and all key/value options in mapString.

If field does not have tag tagName, m will be nil.

See the TagMap* constants for opts.

func TagToMixedMapWithValue

func TagToMixedMapWithValue(field reflect.StructField, tagName string, opts ...tagMapOpt) (value string, mapBool map[string]bool, mapString map[string]string)

TagToMixedMapWithValue combines TagToBoolMapWithValue and TagToStringMapWithValue. It takes struct field `field` and tag name `tagName`, and returns all single-value options in mapBool, and all key/value options in mapString along with the first single-value option as value..

If field does not have tag tagName, m will be nil.

See the TagMap* constants for opts.

func TagToStringMap

func TagToStringMap(field reflect.StructField, tagName string, opts ...tagMapOpt) (m map[string]string)

TagToStringMap takes struct field `field` and tag name `tagName`,

optionally with options `opts`, and returns a map of the tag values.

The tag value string is assumed to be in the form of:

key=value[,key=value,key=value...]

and returns a map[string]string (map[key]value). It is proccessed in order; later duplicate keys overwrite previous ones.

If field does not have tag tagName, m will be nil.

If only a key is provided with no value, the value in the map will be an empty string. (e.g. "foo,bar=baz" => map[string]string{"foo": "", "bar: "baz"}

See the TagMap* constants for opts.

func TagToStringMapWithValue

func TagToStringMapWithValue(field reflect.StructField, tagName string, opts ...tagMapOpt) (value string, m map[string]string)

TagToStringMapWithValue is like TagToStringMap but additionally assumes the first value is an "identifier". The tag value string is assumed to be in the form of:

value,key=value[,key=value,key=value...]

and returns a map[string]string (map[key]value) with the value.

Types

This section is empty.

Jump to

Keyboard shortcuts

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