v

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2022 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetSchemaInJSON

func GetSchemaInJSON(t reflect.Type) ([]byte, error)

GetSchemaInJSON return the json schema of t in json format.

func GetSchemaInYAML

func GetSchemaInYAML(t reflect.Type) ([]byte, error)

GetSchemaInYAML returns the json schema of t in yaml format.

Types

type ContentValidator

type ContentValidator interface {
	Validate([]byte) error
}

ContentValidator is used to validate by data content.

type FormatFunc

type FormatFunc func(v interface{}) error

FormatFunc validates the customized format in json schema. The function could panic if the types are unexpected.

type ValidateRecorder

type ValidateRecorder struct {
	// JSONSchemaErrs generated by vendor json schema.
	JSONSchemaErrs []string `yaml:"jsonschemaErrs,omitempty"`
	// FormatErrs generated by the format function of the single field.
	FormatErrs []string `yaml:"formatErrs,omitempty"`
	// GeneralErrs generated by Validate() of the Validator itself.
	GeneralErrs []string `yaml:"generalErrs,omitempty"`

	// SystemErr stands internal error, which often means bugs.
	SystemErr string `yaml:"systemErr,omitempty"`
}

ValidateRecorder records varied errors after validating.

func Validate

func Validate(v interface{}) *ValidateRecorder

Validate validates by json schema rules, custom formats and general methods.

func (*ValidateRecorder) Error

func (vr *ValidateRecorder) Error() string

func (*ValidateRecorder) String

func (vr *ValidateRecorder) String() string

func (*ValidateRecorder) Valid

func (vr *ValidateRecorder) Valid() bool

Valid represents if the result is valid.

type Validator

type Validator interface {
	Validate() error
}

Validator stands for the types which needs its own Validate function.

Jump to

Keyboard shortcuts

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