Documentation
¶
Overview ¶
Package validation provides field-level input validation helpers that return structured errcode errors suitable for HTTP handlers and service- layer preconditions.
Depends only on stdlib + pkg/errcode to respect the pkg/ layering rule.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsNilInterface ¶
IsNilInterface reports whether v is nil or a typed-nil interface value.
Use this at construction boundaries for interface dependencies. A plain `dep == nil` check misses values such as `var dep *Repo; New(dep)` because the interface carries a non-nil concrete type descriptor.
func RequireNotEmpty ¶
func RequireNotEmpty(code errcode.Code, fields ...NamedValue) error
RequireNotEmpty returns nil when every field's value is non-empty. On the first empty value it returns errcode.New(code, "<field> is required").
Empty means value == ""; whitespace-only strings are NOT trimmed, matching the existing == "" convention across the repo. Callers choose the code to preserve domain-specific classification (ErrAuthIdentityInvalidInput, ErrConfigInvalidInput, etc.).
Usage:
if err := validation.RequireNotEmpty(errcode.ErrAuthIdentityInvalidInput,
validation.F("id", req.ID),
); err != nil {
return err
}
if err := validation.RequireNotEmpty(errcode.ErrAuthLoginInvalidInput,
validation.F("userId", req.UserID),
validation.F("oldPassword", req.OldPassword),
validation.F("newPassword", req.NewPassword),
); err != nil {
return err
}
Types ¶
type NamedValue ¶
NamedValue pairs a field name with its current value for the Require* helpers. Construct with F() for readable call sites.
func F ¶
func F(name, value string) NamedValue
F is shorthand for NamedValue{Name: name, Value: value}.