defaults - Default Values
Overview
The defaults module provides default value setting for Go structs with support for various data types and custom default functions.
Functions
SetDefaults()
Set default values for a struct.
Parameters:
value- Struct pointer to set defaults foropts- Options for default behavior
Options:
ErrorMode- Error handling mode (Panic, Ignore, Return)ValidateDefaults- Whether to validate default valuesAllowOverwrite- Whether to allow overwriting non-zero values
Example:
RegisterCustomDefault()
Register custom default function for a type.
Parameters:
typeName- Type name for registrationfn- Default function
Example:
Usage Patterns
Struct Initialization
Custom Defaults
Error Handling
Best Practices
Default Tags
Related Documentation
- validator - Data validation
- API Documentation
- Module Overview