validation

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// JSONDriver is the JSON struct field driver.
	//
	// Uses `json` field tag.
	JSONDriver = StructFieldDriver(iota)
	// YAMLDriver is the YAML struct field driver.
	//
	// Uses `yaml` field tag.
	YAMLDriver
	// XMLDriver is the XML struct field driver.
	//
	// Uses `xml` field tag.
	XMLDriver
	// TOMLDriver is the TOML struct field driver.
	//
	// Uses `toml` field tag.
	TOMLDriver
)

Variables

This section is empty.

Functions

This section is empty.

Types

type GoPlaygroundValidator

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

GoPlaygroundValidator a concrete implementation of Validator using go-playground/validator package.

func NewGoPlaygroundValidator

func NewGoPlaygroundValidator(config ValidatorConfig) GoPlaygroundValidator

NewGoPlaygroundValidator allocates a new GoPlaygroundValidator instance.

func (GoPlaygroundValidator) Validate

func (g GoPlaygroundValidator) Validate(ctx context.Context, v any) error

Validate validates the given value. Returns error if one or more validations failed.

type StructFieldDriver added in v0.1.3

type StructFieldDriver uint8

StructFieldDriver is the codec algorithm to use for struct tag field scanning.

As validators scan struct fields, some of them might define tags for specific codecs (e.g. json). This causes a mismatch between the base and the encoded names and lead to confusion for routine callers.

A StructFieldDriver defines which tags of a codec mechanism to use for validator operations like error generation.

func NewStructFieldDriver added in v0.1.3

func NewStructFieldDriver(v string) StructFieldDriver

NewStructFieldDriver allocates a new StructFieldDriver instance based on its string value.

Default value is JSONDriver.

func (StructFieldDriver) MarshalText added in v0.1.3

func (d StructFieldDriver) MarshalText() (text []byte, err error)

func (StructFieldDriver) String added in v0.1.3

func (d StructFieldDriver) String() string

func (*StructFieldDriver) UnmarshalText added in v0.1.3

func (d *StructFieldDriver) UnmarshalText(text []byte) error

type Validator

type Validator interface {
	// Validate validates the given value.
	Validate(ctx context.Context, v any) error
}

Validator is a utility component used by systems to validate a certain value and/or structure.

type ValidatorConfig added in v0.1.3

type ValidatorConfig struct {
	StructFieldDriver StructFieldDriver `env:"VALIDATOR_STRUCT_SCANNER_DRIVER" envDefault:"json"`
}

ValidatorConfig is the configuration structure for a Validator instance.

Jump to

Keyboard shortcuts

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