reflectutil

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2024 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetStructFieldValue

func GetStructFieldValue[T any](s T, tagValue string, tagName string) (reflect.Value, bool)

GetStructFieldValue returns the reflect.Value corresponding to the field of struct T whose field has a tag tagName with value tagValue.

For example, given this struct and var declaration:

type S struct {
	Foo string `slug:"foo"
	Bar string `slug:"bar"
}
var s S

GetStructFieldValue(&s, "foo", "slug") will return the reflect.Value corresponding to s.Foo.

func GetTime

func GetTime(v any) (time.Time, bool)

GetTime returns the time.Time that corresponds to the passed value. The value must be either time.Time or sql.Null[time.Time].

func GetType

func GetType(s any) reflect.Type

GetValue gets the type of s, following pointers.

func GetValue

func GetValue(s any) reflect.Value

GetValue gets the value of s, following pointers.

func MapToStruct

func MapToStruct[T any](m map[string]string, tagName string) T

MapToStruct converts a map[string]string into a struct T using values from tag tagName as the keys.

func StructToMap

func StructToMap[T any](s T, tagName string) map[string]any

StructToMap converts struct T into a map[string]any using values from tag tagName as the keys.

func ToString

func ToString(value any) string

ToString returns value converted into a string.

Types

This section is empty.

Jump to

Keyboard shortcuts

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