fielderrors

package
v4.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package fielderrors defines stable field-level validation error shapes.

FieldErrors implements error and Provider so response helpers can map validation failures into Problem Details extensions without depending on a specific validator implementation.

Purpose: See the package summary above. Import: `github.com/aatuh/api-toolkit/v4/fielderrors`. Example: See docs/api-reference.md for package example links and docs/cookbook.md for task recipes. Errors: Constructors, parsers, and handlers return or write documented errors according to their signatures; packages with plain data types do not add hidden error channels. Concurrency: Treat configured middleware and helpers as immutable after construction; request and response values remain request-scoped unless a type documents stronger guarantees. Stability: Stable core API under VERSIONING.md and scripts/apicheck.sh. When not to use: Prefer net/http, application-owned types, or narrower helpers when this package contract is not needed.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FieldError

type FieldError struct {
	Field   string `json:"field,omitempty" example:"postal_code"`
	Code    string `json:"code,omitempty" example:"required"`
	Message string `json:"message,omitempty" example:"postal_code is required"`
}

FieldError describes a single field-level validation failure.

func (FieldError) Error

func (e FieldError) Error() string

type FieldErrors

type FieldErrors []FieldError

FieldErrors is a collection of field-level validation errors.

Example
package main

import (
	"fmt"

	"github.com/aatuh/api-toolkit/v4/fielderrors"
)

func main() {
	errs := fielderrors.FieldErrors{{
		Field:   "name",
		Code:    "required",
		Message: "name is required",
	}}

	fmt.Println(errs.Error())
	fmt.Println(errs.ToMap()["name"])

}
Output:
name is required
name is required

func (FieldErrors) Error

func (e FieldErrors) Error() string

func (FieldErrors) FieldErrors

func (e FieldErrors) FieldErrors() FieldErrors

FieldErrors returns itself to satisfy the Provider interface.

func (FieldErrors) ToMap

func (e FieldErrors) ToMap() map[string]string

ToMap converts field errors into a field->message map.

type Provider

type Provider interface {
	FieldErrors() FieldErrors
}

Provider exposes field errors for downstream mappers.

Jump to

Keyboard shortcuts

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