common

package
v0.53.4 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// OptionalJSONTag uses field names defined in json tags, if available
	OptionalJSONTag = TrimOmitempty(OptionalTag("json"))
)

Functions

func Decode

func Decode(typ reflect.Type, values map[string]string, prefix string, fn FieldName) interface{}

Decode based on the given type, applies all values to hydrate a new instance

func DecodeInto

func DecodeInto(obj interface{}, values map[string]string, prefix string, fn FieldName)

DecodeInto decodes all values to hydrate the given object instance

func Encode

func Encode(obj interface{}, prefix string, fn FieldName) map[string]string

Encode recursively encodes the object's properties as an ordered set of NameValue pairs

func PtrToStruct

func PtrToStruct(ptr interface{}) interface{}

Types

type FieldName

type FieldName func(field reflect.StructField) (string, bool)

FieldName return a flag to indicate this is a valid field and a name to use

func OptionalTag

func OptionalTag(tag string) FieldName

OptionalTag given a tag name, will return the defined tag or fall back to lower camel case field name

func RequiredTag

func RequiredTag(tag string) FieldName

RequiredTag based on the given tag, only use a field if present

func TrimOmitempty

func TrimOmitempty(fn FieldName) FieldName

TrimOmitempty trims `,omitempty` from the name

type NameValue

type NameValue struct {
	Name  string
	Value string
}

NameValue a simple type to store stringified name/value pairs

func Sorted

func Sorted(values map[string]string) (out []NameValue)

Sorted returns a sorted set of NameValue pairs

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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