structs

package
v1.14.5 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2020 License: MIT Imports: 2 Imported by: 0

Documentation

Overview

Package structs provides functions for struct conversion.

Inspired and improved from: https://github.com/fatih/structs

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MapField

func MapField(pointer interface{}, priority []string) (map[string]*Field, error)

MapField retrieves struct field as map[name/tag]*Field from <pointer>, and returns the map.

The parameter <pointer> should be type of struct/*struct.

The parameter <priority> specifies the priority tag array for retrieving from high to low.

Note that it only retrieves the exported attributes with first letter up-case from struct.

func TagMapField

func TagMapField(pointer interface{}, priority []string) (map[string]*Field, error)

TagMapField retrieves struct tags as map[tag]*Field from <pointer>, and returns it.

The parameter <pointer> should be type of struct/*struct.

Note that it only retrieves the exported attributes with first letter up-case from struct.

func TagMapName

func TagMapName(pointer interface{}, priority []string) (map[string]string, error)

TagMapName retrieves struct tags as map[tag]attribute from <pointer>, and returns it.

The parameter <pointer> should be type of struct/*struct.

Note that it only retrieves the exported attributes with first letter up-case from struct.

Types

type Field

type Field struct {

	// Retrieved tag value. There might be more than one tags in the field,
	// but only one can be retrieved according to calling function rules.
	TagValue string
	// contains filtered or unexported fields
}

Field contains information of a struct field .

func TagFields added in v1.10.1

func TagFields(pointer interface{}, priority []string) ([]*Field, error)

TagFields retrieves struct tags as []*Field from <pointer>, and returns it.

The parameter <pointer> should be type of struct/*struct.

Note that it only retrieves the exported attributes with first letter up-case from struct.

func (*Field) IsEmbedded added in v1.14.3

func (f *Field) IsEmbedded() bool

IsEmbedded returns true if the given field is an anonymous field (embedded)

func (*Field) IsExported added in v1.14.3

func (f *Field) IsExported() bool

IsExported returns true if the given field is exported.

func (*Field) Name added in v1.14.3

func (f *Field) Name() string

Name returns the name of the given field

func (*Field) Tag added in v1.10.1

func (f *Field) Tag(key string) string

Tag returns the value associated with key in the tag string. If there is no such key in the tag, Tag returns the empty string.

func (*Field) Value added in v1.14.3

func (f *Field) Value() interface{}

Value returns the underlying value of the field. It panics if the field is not exported.

Jump to

Keyboard shortcuts

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