reflections

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fields

func Fields(obj interface{}) ([]string, error)

Fields returns the struct fields names list. obj can whether be a structure or pointer to structure.

func FieldsDeep

func FieldsDeep(obj interface{}) ([]string, error)

FieldsDeep returns "flattened" fields (fields from anonymous inner structs are treated as normal fields)

func GetField

func GetField(obj interface{}, name string) (interface{}, error)

GetField returns the value of the provided obj field. obj can whether be a structure or pointer to structure.

func GetFieldKind

func GetFieldKind(obj interface{}, name string) (reflect.Kind, error)

GetFieldKind returns the kind of the provided obj field. obj can whether be a structure or pointer to structure.

func GetFieldTag

func GetFieldTag(obj interface{}, fieldName, tagKey string) (string, error)

GetFieldTag returns the provided obj field tag value. obj can whether be a structure or pointer to structure.

func GetFieldType

func GetFieldType(obj interface{}, name string) (string, error)

GetFieldType returns the kind of the provided obj field. obj can whether be a structure or pointer to structure.

func HasField

func HasField(obj interface{}, name string) (bool, error)

HasField checks if the provided field name is part of a struct. obj can whether be a structure or pointer to structure.

func Items

func Items(obj interface{}) (map[string]interface{}, error)

Items returns the field - value struct pairs as a map. obj can whether be a structure or pointer to structure.

func ItemsDeep

func ItemsDeep(obj interface{}) (map[string]interface{}, error)

FieldsDeep returns "flattened" items (fields from anonymous inner structs are treated as normal fields)

func SetField

func SetField(obj interface{}, name string, value interface{}) error

SetField sets the provided obj field with provided value. obj param has to be a pointer to a struct, otherwise it will soundly fail. Provided value type should match with the struct field you're trying to set.

func Tags

func Tags(obj interface{}, key string) (map[string]string, error)

Tags lists the struct tag fields. obj can whether be a structure or pointer to structure.

func TagsDeep

func TagsDeep(obj interface{}, key string) (map[string]string, error)

FieldsDeep returns "flattened" tags (fields from anonymous inner structs are treated as normal fields)

Types

This section is empty.

Jump to

Keyboard shortcuts

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