ns

package
v0.0.0-...-a1d7b1b Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AlwaysFalse

func AlwaysFalse(_ string, _ reflect.Type) bool

func AlwaysTrue

func AlwaysTrue(_ string, _ reflect.Type) bool

func FromCompositeObject

func FromCompositeObject(object interface{}, current string, namespace *[]string, options ...OptionFunc) error

CompositeObjectToNs inspects an object to construct a list of paths to data.

Operation of this method is controlled by options, which default to:

InspectEmptyContainers(AlwaysTrue),
InspectNilPointers(AlwaysTrue),
EntryForContainersRoot(AlwaysFalse),
ExportJsonFieldNames(AlwaysTrue),
WildcardEntryInContainer(AlwaysFalse),
SanitizeNamespaceParts(AlwaysTrue).

Different options may be specified to implement selective and context-sensitive inspection.

func FromComposition

func FromComposition(object interface{}, current string, namespace *[]string) error

FromComposition constructs list of namespaces from multilevel struct compositions using field names as namespace entries. 'Current' value is prefixed to all namespace elements. It returns nil in case of success or error if building namespaces failed.

func FromCompositionTags

func FromCompositionTags(object interface{}, current string, namespace *[]string) error

FromCompositionTags constructs list of namespaces from multilevel struct composition using field tags as namespace entries. 'Current' value is prefixed to all namespace elements. It returns nil in case of success or error if building namespaces failed.

func FromJSON

func FromJSON(data *[]byte, current string, namespace *[]string) error

FromJSON constructs list of namespaces from json document using json literals as namespace entries. 'Current' value is prefixed to all namespace elements. It returns nil in case of success or error if building namespaces failed.

func FromMap

func FromMap(m map[string]interface{}, current string, namespace *[]string) error

FromMap constructs list of namespaces from multilevel map using map keys as namespace entries. 'Current' value is prefixed to all namespace elements. It returns nil in case of success or error if building namespaces failed.

func GetStructValueByNamespace

func GetStructValueByNamespace(object interface{}, ns []string) interface{}

GetStructValueByNamespace returns value stored in struct composition. It requires filed tags on each struct field which may be represented as namespace component. It iterates over fields recursively, checks tags until it finds leaf value.

func GetValueByNamespace

func GetValueByNamespace(object interface{}, ns []string) interface{}

GetValueByNamespace returns value stored in nested map, array or struct composition. TODO Implementation of handling complex compositions with map/slice

func ReplaceNotAllowedCharsInNamespacePart

func ReplaceNotAllowedCharsInNamespacePart(ns string) string

ReplaceNotAllowedCharsInNamespacePart replaces not allowed characters in namespace part by '_'

func ValidateMetricNamespacePart

func ValidateMetricNamespacePart(ns string) error

ValidateMetricNamespacePart checks if namespace part contains not allowed characters

Types

type FlagFunc

type FlagFunc (func(nsPath string, itemKind reflect.Type) bool)

type OptionFunc

type OptionFunc (func() (int, FlagFunc))

func EntryForContainersRoot

func EntryForContainersRoot(flagFunc FlagFunc) OptionFunc

EntryForContainersRoot controls inserting entries for containers themselves.

If EntryForContainersRoot returns true for container at some path in ns, ns will contain entry for a container itself.

func ExportJsonFieldNames

func ExportJsonFieldNames(flagFunc FlagFunc) OptionFunc

ExportJsonFieldNames option controls naming fields of struct where field is annotated with json tag.

If ExportJsonFieldNames returns true for struct at some path in ns, json name for all fields will be used rather than fields' own names. If json tag contains dash ('-') for any field, field won't be exported.

func InspectEmptyContainers

func InspectEmptyContainers(flagFunc FlagFunc) OptionFunc

InspectEmptyContainers option controls NS expansion for empty maps.

If InspectEmptyContainers returns true for map at some path in ns, ns will be expanded for map's value type

func InspectNilPointers

func InspectNilPointers(flagFunc FlagFunc) OptionFunc

InspectNilPointers option controls NS expansion for nil pointers.

If InspectNilPointers returns true for nil pointer at some path in ns, ns will be expanded for pointer's original type

func SanitizeNamespaceParts

func SanitizeNamespaceParts(flagFunc FlagFunc) OptionFunc

SanitizeNamespaceParts controls sanitizing namespace parts in generated namespace.

If SanitizeNamespaceParts returns true for object at some path in ns, all child keys of that object (fields, map keys) will have their names sanitized, ie. all the invalid characters removed.

See also: ns.ReplaceNotAllowedCharsInNamespacePart

func WildcardEntryInContainer

func WildcardEntryInContainer(flagFunc FlagFunc) OptionFunc

WildcardEntryInContainer controls adding a wildcard for inspected non-empty containers.

If WildcardEntryInContainer returns true for non-empty container (map/ slice/ array) at some path in ns, a wildcard entry will be reported for container and the containers' value type will be inspected in depth.

See also: InspectEmptyContainers

Jump to

Keyboard shortcuts

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