reflector

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2021 License: MIT Imports: 6 Imported by: 1

README

Reflector

Travis Build Go Report Card GoDoc codecov MIT License

Easy reflection on structs with handle applications

go get -u github.com/vporoshok/reflector

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractTagsFromStruct

func ExtractTagsFromStruct(tagName string, i interface{}) []string

ExtractTagsFromStruct returns list of tag values

func StructToMapByTags

func StructToMapByTags(tagName string, i interface{}, skipNils bool) map[string]interface{}

StructToMapByTags shortcut to Reflector.ExtractValues

Types

type ExtractOption

type ExtractOption interface {
	Apply(extractConfig) extractConfig
}

ExtractOption an option for Reflector.ExtractValues and Reflector.ExtractTags.

func WithoutEmbedded

func WithoutEmbedded() ExtractOption

WithoutEmbedded skip embedded structures.

func WithoutEmpty

func WithoutEmpty() ExtractOption

WithoutEmpty skip fields without tag.

func WithoutMinus

func WithoutMinus() ExtractOption

WithoutMinus skip fields with tag setted to minus sign.

type Reflector

type Reflector struct {
	// contains filtered or unexported fields
}

Reflector of structure.

func FromValue

func FromValue(v reflect.Value) Reflector

FromValue is an constructor from existed reflect.Value.

func New

func New(i interface{}) Reflector

New is an constructor from structure instance.

func (Reflector) Apply

func (r Reflector) Apply(m map[string]string) error

Apply hash-table to reflected variable.

func (Reflector) ExtractTags

func (r Reflector) ExtractTags(tagName string, opts ...ExtractOption) map[string]string

ExtractTags returns hash-map which field value refer to tag value

func (Reflector) ExtractValues

func (r Reflector) ExtractValues(tagName string, skipNils bool, opts ...ExtractOption) map[string]interface{}

ExtractValues returns hash-map which tag value refer to field value.

func (Reflector) Value

func (r Reflector) Value() interface{}

Value of reflected variable.

Jump to

Keyboard shortcuts

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