validate

package
v0.5.4 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2026 License: MIT Imports: 4 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func NewValidator() *validator.Validate

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 Struct

func Struct(v *validator.Validate, s any) (string, bool)

Struct validates a struct and returns a formatted error string, or "" if valid.

func ToSnakeCase

func ToSnakeCase(s string) string

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:

  1. previous char is lowercase → leaving a word, entering an acronym or a new word: `userID` → `user_ID`, `myValue` → `my_Value`
  2. 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.

Jump to

Keyboard shortcuts

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