structs

package
v0.0.0-...-c1fbc2c Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AssignToField

func AssignToField[T any](obj *T, fieldName string, stringEncodedValue string) error

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

func MetadataFromType(reflectType reflect.Type) *readonly.Map[string, *FieldMetadata]

MetadataFromType returns a map of a structs field names to their respective metadata.

func ValueFromName

func ValueFromName[T any](structInstance T, fieldName string) (reflect.Value, error)

ValueFromName returns the fields value if it exists.

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.

Jump to

Keyboard shortcuts

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