structutils

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2025 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FieldNames added in v1.9.0

func FieldNames[T any](structInstance T, structTags ...string) []string

FieldNames returns field names, optionally using struct tags for naming. If struct tags are provided, uses the first matching tag value as the field name. Omits fields with tag value "-".

func Fields added in v1.9.0

func Fields[T any](structInstance T) []string

Fields returns a slice of field names from a struct.

func ForEach

func ForEach[T any](structInstance T, function func(key string, value any, tag reflect.StructTag))

ForEach given a struct, calls the passed in function with each visible struct field's name, value and tag.

func GetField added in v1.9.0

func GetField[T any](structInstance T, fieldName string) (any, bool)

GetField retrieves the value of a field by name. Returns the value and true if found, zero value and false if not found.

func HasField added in v1.9.0

func HasField[T any](structInstance T, fieldName string) bool

HasField checks if a struct has a field with the given name.

func ToMap

func ToMap[T any](structInstance T, structTags ...string) map[string]any

ToMap given a struct, converts it to a map[string]any. This function also takes struct tag names as optional parameters - if passed in, the struct tags will be used to remap or omit values.

func Values added in v1.9.0

func Values[T any](structInstance T) []any

Values returns a slice of field values from a struct.

Types

This section is empty.

Jump to

Keyboard shortcuts

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