reflect

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package reflect provides utilities for traversing struct fields and values during template evaluation, supporting both field names and JSON tags.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CanDescend

func CanDescend(v any) bool

CanDescend returns true if v is a type that can have fields/elements accessed.

func IsSlice added in v0.0.7

func IsSlice(v any) bool

IsSlice reports whether v is a slice or array.

func PopulateStructFields

func PopulateStructFields(m map[string]any, data any)

PopulateStructFields adds exported struct fields to the map using JSON tags. Nested structs are converted to maps to support path resolution like item.inStock.

func ResolveValue

func ResolveValue(v any, fieldName string) (any, bool)

ResolveValue traverses a value by field access (supporting nested structs, maps, slices). Field access can use either the struct field name or its JSON tag (if present). Returns (value, true) if resolution succeeds, (nil, false) otherwise.

func SliceToAny added in v0.0.7

func SliceToAny(s any) []any

SliceToAny converts any typed slice to []any. Returns nil if the input is not a slice.

func StructToMap

func StructToMap(data any) map[string]any

StructToMap converts a struct to a map using JSON tags for keys. Nested structs are recursively converted to maps as well.

Types

This section is empty.

Jump to

Keyboard shortcuts

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