Documentation
¶
Index ¶
- func AssignToField[T any](obj *T, fieldName string, stringEncodedValue string) error
- func Metadata[T any]() *readonly.Map[string, *FieldMetadata]
- func MetadataFromType(reflectType reflect.Type) *readonly.Map[string, *FieldMetadata]
- func ValueFromName[T any](structInstance T, fieldName string) (reflect.Value, error)
- type FieldMetadata
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssignToField ¶
AssignToField sets a struct field specified by its name to a provided value encoded as a string. The function handles various data types including basic types (string, int, etc.), complex types (structs, slices, maps) and types implementing the encoding.TextUnmarshaler interface. The conversion from string to the appropriate type is performed based on the field's underlying type. JSON format is expected for complex types. This function supports setting both direct values and pointers to the values.
func Metadata ¶
func Metadata[T any]() *readonly.Map[string, *FieldMetadata]
Metadata returns a map of a structs field names to their respective metadata.
func MetadataFromType ¶
MetadataFromType returns a map of a structs field names to their respective metadata.
Types ¶
type FieldMetadata ¶
type FieldMetadata struct {
// contains filtered or unexported fields
}
FieldMetadata is the metadata extracted a struct fields.
func (*FieldMetadata) Anonymous ¶
func (f *FieldMetadata) Anonymous() *readonly.Slice[string]
Anonymous returns the anonymous struct name chain before getting to a field.
type DeepExample struct { DeepField string } type Example struct { DeepExample Field string }
If calling Anonymous on the struct Example and the field DeepField, ["DeepExample"] would be returned.
func (*FieldMetadata) Tags ¶
func (f *FieldMetadata) Tags() *readonly.Map[string, string]
Tags returns a map of tag names to its respective tag content.
func (*FieldMetadata) Type ¶
func (f *FieldMetadata) Type() reflect.Type
Type returns the fields type.