validator

package
v0.0.0-...-95995d7 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2024 License: MIT Imports: 8 Imported by: 2

Documentation

Overview

Each Validator have at least two process methods, one for 'Parsing' and one for 'Validating'.

In 'Parsing' stage, we call validator as 'Creator', and it will be register to some 'Mgr' for caching.

Parsing

There are common 'Rule DSL' below:

// simple
@name

// with parameters
@name<param1>
@name<param1,param2>

// with ranges
@name[from, to)
@name[length]

// with values
@name{VALUE1,VALUE2,VALUE3}
@name{%v}

// with regexp
@name/\d+/

// optional and default value
@name?
@name = value
@name = 'some string value'

// composes
@map<@string[1,10],@string{A,B,C}>
@map<@string[1,10],@string/\d+/>[0,10]

Then the parsed rule will be transform to special validators:

Validating

We can create validator by 'Rule DSL', and also can configure them by validator struct field as conditions. Then call the method `Validate(v any) error` to do value validations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(out any, options ...jsontext.Options) ([]byte, error)

func MarshalEncode

func MarshalEncode(enc *jsontext.Encoder, out any, options ...jsontext.Options) error

func MarshalWrite

func MarshalWrite(w io.Writer, out any, options ...jsontext.Options) error

func Register

func Register(creator Creator)

func Unmarshal

func Unmarshal(in []byte, out any, options ...jsontext.Options) error

func UnmarshalDecode

func UnmarshalDecode(dec *jsontext.Decoder, out any, options ...jsontext.Options) error

func UnmarshalRead

func UnmarshalRead(r io.Reader, out any, options ...jsontext.Options) error

Types

type Creator

type Creator = internal.ValidatorProvider

type Option

type Option = internal.ValidatorOption

type Validator

type Validator = internal.Validator

func New

func New(option Option) (Validator, error)

Directories

Path Synopsis
Package errors GENERATED BY gengo:runtimedoc DON'T EDIT THIS FILE
Package errors GENERATED BY gengo:runtimedoc DON'T EDIT THIS FILE
Package internal GENERATED BY gengo:runtimedoc DON'T EDIT THIS FILE
Package internal GENERATED BY gengo:runtimedoc DON'T EDIT THIS FILE
rules
+gengo:runtimedoc=false
+gengo:runtimedoc=false
Package validators GENERATED BY gengo:runtimedoc DON'T EDIT THIS FILE
Package validators GENERATED BY gengo:runtimedoc DON'T EDIT THIS FILE

Jump to

Keyboard shortcuts

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