validation

package
v1.0.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 14 Imported by: 0 modules, 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

Overview

Code generated by genx:code@v0.4.2 DO NOT EDIT.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultRuleByType

func DefaultRuleByType(t reflect.Type) string

func IsValidationError

func IsValidationError(err error) bool

func PrefixPointer

func PrefixPointer(err error, prefix jsontext.Pointer) error

PrefixPointer prepends prefix to the pointers in err. It is used when err comes from a nested document whose root is located by prefix in the outer document, eg: a request body is located by `/body` in the request.

func Register

func Register(p Provider)

func UnmarshalDecode

func UnmarshalDecode(d *jsontext.Decoder, v any, o ...json.Options) error

func WrapPointer

func WrapPointer(err error, p jsontext.Pointer) error

WrapPointer attaches pointer p to err. p is a JSON Pointer (RFC 6901) in the same document as the pointers already in err, so an existing pointer is kept since it is the innermost and the most precise one.

Types

type Error

type Error int8

Error validation error +genx:code

const (
	ERROR_UNDEFINED           Error = iota
	ERROR__STRING_LENGTH_MODE       // invalid string length mode, expect 'byte' or 'rune'
	ERROR__NOT_MATCH_REGEXP         // invalid string not match regexp
	ERROR__SLICE_PARAM              // invalid string parameter
	ERROR__MAP_PARAM                // invalid map parameter
	ERROR__INPUT_TYPE               // invalid input: invalid type
	ERROR__INPUT_VALUE              // invalid input: invalid value
	ERROR__MISSING_REQUIRED         // invalid input: missing required
	ERROR__UNREGISTERED_RULE        // unregistered rule
	ERROR__DEC_INVALID_INPUT        // decoder: invalid input, expecting a pointer value
)

func (Error) CodeIdentifier

func (e Error) CodeIdentifier() string

CodeIdentifier returns the unique identifier of the code

func (Error) CodeValues

func (Error) CodeValues() []any

CodeValues implements codex.CanBeCode

func (Error) Message

func (e Error) Message() string

Message presents error message

type Option

type Option struct {
	Type reflect.Type
	Rule rule.Rule
	Text bool
}

type PointerError

type PointerError struct {
	// contains filtered or unexported fields
}

PointerError locates err by a JSON Pointer (RFC 6901) in the request document.

func (*PointerError) Error

func (e *PointerError) Error() string

func (*PointerError) Pointer

func (e *PointerError) Pointer() jsontext.Pointer

func (*PointerError) Unwrap

func (e *PointerError) Unwrap() error

type PostValidator

type PostValidator interface {
	PostValidate(reflect.Value) error
}

type Provider

type Provider interface {
	Name() string
	Variants() []string

	New(rule.Rule) (Validator, error)
}

type TagValidator

type TagValidator interface {
	ValidationTag() string
}

type UnmarshalDecoder

type UnmarshalDecoder interface {
	UnmarshalDecode(d *jsontext.Decoder, o ...json.Options) error
}

func Any

func Array

func Basic

func Map

func Pointer

func Pointer(rv reflect.Value, va Validator) UnmarshalDecoder

func Struct

func Struct(rv reflect.Value, va Validator) UnmarshalDecoder

func Text

func Value

type Validator

type Validator interface {
	String() string
	Validate([]byte) error
}

func New

func New(option Option) (Validator, error)

func NewFromStructField

func NewFromStructField(f *scanner.Field) (Validator, error)

type WithDefaults

type WithDefaults interface {
	Defaults() []byte
}

type WithElemRule

type WithElemRule interface {
	ElemRule() rule.Rule
}

type WithKeyRule

type WithKeyRule interface {
	KeyRule() rule.Rule
}

type WithOptional

type WithOptional interface {
	Optional() bool
}

Directories

Path Synopsis
Code generated by genx:code@v0.4.2 DO NOT EDIT.
Code generated by genx:code@v0.4.2 DO NOT EDIT.
Code generated by genx:code@v0.4.2 DO NOT EDIT.
Code generated by genx:code@v0.4.2 DO NOT EDIT.

Jump to

Keyboard shortcuts

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