Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FormatFieldError ¶
func FormatFieldError(e validator.FieldError) string
FormatFieldError formats a single field error into a human-readable message.
func FormatValidationErrors ¶
func FormatValidationErrors(errs validator.ValidationErrors) string
FormatValidationErrors formats validation errors into a human-readable string.
func NewValidator ¶
NewValidator creates a validator instance with custom rules (ULID) registered. It panics if a custom validation rule cannot be registered; the only documented failure mode is an invalid tag name or nil function, both of which would be a programmer error caught at first run rather than a runtime condition.
func ToSnakeCase ¶
ToSnakeCase converts a PascalCase or camelCase string to snake_case. Handles acronyms correctly: `UserID` → `user_id`, `HTTPStatusCode` → `http_status_code`. The previous shape walked uppercase letters one at a time, producing `user_i_d` / `h_t_t_p_status_code` — neither of those matches any Go-stdlib convention and the result leaks into validation error messages users see (#140).
Rule: insert `_` before an uppercase letter at position i > 0 when either of the following transitions holds:
- previous char is lowercase → leaving a word, entering an acronym or a new word: `userID` → `user_ID`, `myValue` → `my_Value`
- previous char is uppercase AND next char is lowercase → end of acronym, start of a new word: `HTTPStatus` → `HTTP_Status`, `userID` keeps `ID` together because `D` has no lowercase next.
Both rules then lowercase the uppercase letter. Digits + non-ASCII runes pass through unchanged (they don't trigger transitions).
Types ¶
This section is empty.