validator

package
v0.0.0-...-ed9fe1d Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2018 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Overview

Package validator provides types and functions for validator implementations

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FieldError

type FieldError struct {
	Message string                 `json:"message"`
	Params  map[string]interface{} `json:"params,omitempty"`
}

FieldError represents an error in the validated object. It has a Message field which is a error message template, and Params map which would be applied to the error message.

func NewFieldError

func NewFieldError(message string, params map[string]interface{}) *FieldError

NewFieldError creates a new ValidationError object.

func (*FieldError) Error

func (v *FieldError) Error() string

Returns string representation of the error.

func (*FieldError) String

func (v *FieldError) String() string

Returns string representation of the error

type FormValidator

type FormValidator struct {
	*Validator
	// contains filtered or unexported fields
}

FormValidator is a validator to validate url.Value

func NewFormValidator

func NewFormValidator() *FormValidator

NewFormValidator returns a new *FormValidator

func (*FormValidator) BoolField

func (f *FormValidator) BoolField(name string) *List

BoolField - a named field for the bool value.

func (*FormValidator) DateField

func (f *FormValidator) DateField(name string) *List

DateField - a named field for the time.Time value (formatted as xtime.ParseDate compatible).

func (*FormValidator) DateTimeField

func (f *FormValidator) DateTimeField(name string) *List

DateTimeField - a named field for the time.Time value (formatted as xtime.Parse compatible).

func (*FormValidator) DurationField

func (f *FormValidator) DurationField(name string) *List

DurationField - a named field for the time.Duration value.

func (*FormValidator) Eval

func (f *FormValidator) Eval(values url.Values) *ValidationError

Eval evaluates the `values` and returns the error if the validation fails.

func (*FormValidator) FloatField

func (f *FormValidator) FloatField(name string) *List

FloatField - a named field for the float value.

func (*FormValidator) IntField

func (f *FormValidator) IntField(name string) *List

IntField - a named field for the int value.

func (*FormValidator) TimeField

func (f *FormValidator) TimeField(name string) *List

TimeField - a named field for the time.Time value (formatted as xtime.ParseTime compatible).

type Func

type Func func(v interface{}) *FieldError

Func is a function to validate the value `v`

type List

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

List is a list of Func

func NewList

func NewList() *List

NewList returns a new *List

func (*List) Func

func (l *List) Func(f func(v interface{}) *FieldError) *List

Func to run the given custom validation fucntion `f`.

func (*List) Match

func (l *List) Match(str string) *List

Match validates the value matches `str`

func (*List) Max

func (l *List) Max(n int64) *List

Max validates the value is more than or equal to `n`

func (*List) Min

func (l *List) Min(n int64) *List

Min validates the value is more than or equal to `n`

func (*List) Required

func (l *List) Required() *List

Required is a function to validate the object is not a nil

func (*List) Unmatch

func (l *List) Unmatch(str string) *List

Unmatch validates the value does not matche `str`

type Validatable

type Validatable interface {
	Value() interface{}
	Get(string) (interface{}, error)
}

Validatable is an interface for an object to be validated

func NewValidatable

func NewValidatable(i interface{}) Validatable

NewValidatable returns a Validatable for any types of struct object

type ValidationError

type ValidationError struct {
	Errors map[string][]*FieldError `json:"errors"`
	Value  interface{}              `json:"value"`
}

ValidationError is an error returned by Eval(Validator, interface{})

type Validator

type Validator struct {
	*List // object validators
	// contains filtered or unexported fields
}

Validator is a struct that contains validator functions

func NewValidator

func NewValidator() *Validator

NewValidator returns a new *BaseValidator

func (*Validator) Eval

func (v *Validator) Eval(i interface{}) *ValidationError

Eval to evaluate the object t and return the validation result. nil would be returned on no validation errors.

func (*Validator) Field

func (v *Validator) Field(name string) *List

Field returns a *List for the given field.

Jump to

Keyboard shortcuts

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