reflectutils

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: May 16, 2024 License: Apache-2.0 Imports: 7 Imported by: 5

Documentation

Index

Constants

View Source
const (
	TAG_AMBIGUOUS_PREFIX  = "yunion-ambiguous-prefix"
	TAG_DEPRECATED_BY     = "yunion-deprecated-by"
	TAG_OLD_DEPRECATED_BY = "deprecated-by"
)

Variables

This section is empty.

Functions

func ExpandInterface

func ExpandInterface(val interface{}) []interface{}

func FillEmbededStructValue

func FillEmbededStructValue(container reflect.Value, embed reflect.Value) bool

func FindAnonymouStructPointer

func FindAnonymouStructPointer(data interface{}, targetPtr interface{}) error

func FindStructFieldInterface

func FindStructFieldInterface(dataValue reflect.Value, name string) (interface{}, bool)

func FindStructFieldValue

func FindStructFieldValue(dataValue reflect.Value, name string) (reflect.Value, bool)

func SetStructFieldValue

func SetStructFieldValue(structValue reflect.Value, fieldName string, val reflect.Value) bool

func StructContains

func StructContains(type1 reflect.Type, type2 reflect.Type) bool

Types

type SEmbedStructFieldValue

type SEmbedStructFieldValue struct {
	Field reflect.Value
	Value reflect.Value
}

type SStructFieldInfo

type SStructFieldInfo struct {
	// True if the field has json tag `json:"-"`
	Ignore    bool
	OmitEmpty bool
	OmitFalse bool
	OmitZero  bool

	// Name can take the following values, in descreasing preference
	//
	//  1. value of "name" tag, e.g. `name:"a-name"`
	//  2. name of "json" tag, when it's not for ignoration
	//  3. kebab form of FieldName concatenated with "_" when Ignore is false
	//  4. empty string
	Name      string
	FieldName string

	ForceString bool
	Tags        map[string]string
	// contains filtered or unexported fields
}

SStructFieldInfo describes struct field, especially behavior for (json) marshal

This struct has unexported fields initialized by exported functions in this package. Do not construct a literal or modify the exported fields in an unmanaged way

func ParseFieldJsonInfo

func ParseFieldJsonInfo(name string, tag reflect.StructTag) SStructFieldInfo

func ParseStructFieldJsonInfo

func ParseStructFieldJsonInfo(sf reflect.StructField) SStructFieldInfo

func (*SStructFieldInfo) MarshalName

func (info *SStructFieldInfo) MarshalName() string

MarshalName returns Name when it's not empty, otherwise it returns kebab form of the field name concatenated with "_"

type SStructFieldValue

type SStructFieldValue struct {
	Info  *SStructFieldInfo
	Value reflect.Value

	Parent *SEmbedStructFieldValue
}

type SStructFieldValueSet

type SStructFieldValueSet []SStructFieldValue

func FetchAllStructFieldValueSet

func FetchAllStructFieldValueSet(dataValue reflect.Value) SStructFieldValueSet

func FetchAllStructFieldValueSetForWrite

func FetchAllStructFieldValueSetForWrite(dataValue reflect.Value) SStructFieldValueSet

func FetchStructFieldValueSet

func FetchStructFieldValueSet(dataValue reflect.Value) SStructFieldValueSet

func FetchStructFieldValueSetForWrite

func FetchStructFieldValueSetForWrite(dataValue reflect.Value) SStructFieldValueSet

func (SStructFieldValueSet) GetInterface

func (set SStructFieldValueSet) GetInterface(name string) (interface{}, bool)

func (SStructFieldValueSet) GetStructFieldIndex

func (fields SStructFieldValueSet) GetStructFieldIndex(name string) int

func (SStructFieldValueSet) GetStructFieldIndexes

func (fields SStructFieldValueSet) GetStructFieldIndexes(name string) []int

func (SStructFieldValueSet) GetStructFieldIndexes2

func (fields SStructFieldValueSet) GetStructFieldIndexes2(name string, strictMode bool) []int

func (SStructFieldValueSet) GetStructFieldIndexesMap

func (fields SStructFieldValueSet) GetStructFieldIndexesMap() map[string][]int

func (SStructFieldValueSet) GetValue

func (set SStructFieldValueSet) GetValue(name string) (reflect.Value, bool)

Jump to

Keyboard shortcuts

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