validation

package
v0.1.0-develop.2026061... Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: MIT Imports: 2 Imported by: 0

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

func IsNilInterface(v any) bool

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

type NamedValue struct {
	Name  string
	Value string
}

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}.

Jump to

Keyboard shortcuts

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