validation

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Code generated by genx:code DO NOT EDIT.

Index

Examples

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 Register

func Register(p Provider)

func UnmarshalDecode

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

func WrapLocationError

func WrapLocationError(err error, location string) error
Example
wp := WrapPositionError(errors.New("wp"), "pos")
fmt.Println(wp)

wl := WrapLocationError(errors.New("wl"), "loc")
fmt.Println(wl)

fmt.Println(WrapLocationError(wp, "loc"))
fmt.Println(WrapPositionError(wl, "pos"))

fmt.Println(WrapPositionError(nil, ""))
fmt.Println(WrapLocationError(nil, ""))
Output:
wp: [pos:pos]
wl: [loc:loc]
wp: [pos:pos]: [loc:loc pos:pos]
wl: [loc:loc]: [loc:loc pos:pos]
<nil>
<nil>

func WrapPositionError

func WrapPositionError[Pos ~string](err error, position Pos) error

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) Message

func (e Error) Message() string

type LocationError

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

func (*LocationError) Error

func (e *LocationError) Error() string

func (*LocationError) Location

func (e *LocationError) Location() string

func (*LocationError) Unwrap

func (e *LocationError) Unwrap() error

type Option

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

type PositionError

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

func (*PositionError) Error

func (e *PositionError) Error() string

func (*PositionError) Position

func (e *PositionError) Position() string

func (*PositionError) Unwrap

func (e *PositionError) 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 DO NOT EDIT.
Code generated by genx:code DO NOT EDIT.
Code generated by genx:code DO NOT EDIT.
Code generated by genx:code DO NOT EDIT.

Jump to

Keyboard shortcuts

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