conv

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func As

func As[T any](v any) (T, error)

As converts v to the desired type T using reflection.

func MapToStruct

func MapToStruct(m map[string]any, dest any) error

MapToStruct copies values from map m to the struct pointed to by dest. Keys are matched to struct fields using orm tags or snake_case names.

func MapsToStructs

func MapsToStructs(src []map[string]any, dest any) error

MapsToStructs converts a slice of maps to a slice of structs.

func StructToMap added in v0.3.0

func StructToMap(v any) (map[string]any, error)

StructToMap converts a struct or pointer to struct into a map. Column names are determined by `db` or `orm` tags, falling back to snake_case field names. Fields tagged with `db:"-"` are omitted. Zero-value fields are included unless the tag contains `omitempty`.

func Value

func Value[T any](m map[string]any, key string) (T, error)

Value returns the given key from m converted to T.

Types

This section is empty.

Jump to

Keyboard shortcuts

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