Utilities
The type-coercion helpers behind field binding, exported for direct use.
The structs/utils package holds the coercion helpers that turn a loosely-typed input value into a concrete field type. Binding uses them internally, and they are exported so you can convert values yourself, for example inside a custom rule.
import "github.com/toaweme/structs/utils"func ToInt(value any) (int, error)Coerces value to an int, parsing a numeric string and truncating a float.
func ToFloat(value any) (float64, error)Coerces value to a float64, parsing a numeric string.
func ToString(value any) (string, error)Coerces value to its string form.
func ParseBool(val string) boolParses a boolean from a string, accepting the usual truthy spellings. Unlike the others it returns no error, falling back to false.
func ToAnySlice(value any) ([]any, error)Normalizes a slice value into []any, the shape the binder iterates when filling a slice field.