fields

package
v1.0.0-rc.0 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2018 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BooleanErrors = map[uint]string{
	codes.Unknown:  "Unknown error.",
	codes.Required: "This field is required.",
	codes.Invalid:  "Ensure this value is a valid boolean.",
}

BooleanErrors is a code-error mapping for Boolean field.

View Source
var DatetimeErrors = map[uint]string{
	codes.Required: "This field is required.",
	codes.Invalid:  "Ensure this value is a valid datetime string.",
}

DatetimeErrors is a code-error mapping for Datetime field.

View Source
var EmailErrors = map[uint]string{
	codes.Required: "This field is required.",
	codes.Invalid:  "Ensure this value is valid email string.",
}

EmailErrors is a code-error mapping for Email field.

View Source
var FloatErrors = map[uint]string{
	codes.Required: "This field is required.",
	codes.Invalid:  "Ensure this value is a valid float.",
	codes.MinValue: "Ensure this value is greater than or equal to %f.",
	codes.MaxValue: "Ensure this value is less than or equal to %f.",
}

FloatErrors is a code-error mapping for Float field.

View Source
var IntegerErrors = map[uint]string{
	codes.Required: "This field is required.",
	codes.Invalid:  "Ensure this value is valid integer.",
	codes.MinValue: "Ensure this value is greater than or equal to %d.",
	codes.MaxValue: "Ensure this value is less than or equal to %d.",
}

IntegerErrors is a code-error mapping for Integer field.

View Source
var StringErrors = map[uint]string{
	codes.Required:  "This field is required.",
	codes.Invalid:   "Ensure this value is valid string.",
	codes.Blank:     "Blank strings aren't allowed.",
	codes.MinLength: "Ensure this value has at least %d characters.",
	codes.MaxLength: "Ensure this value has at most %d characters.",
}

StringErrors is a code-error mapping for String field.

View Source
var URLErrors = map[uint]string{
	codes.Required: "This field is required.",
	codes.Invalid:  "Ensure this value is valid URL string.",
}

URLErrors is a code-error mapping for URL field.

Functions

This section is empty.

Types

type Boolean

type Boolean struct {
	Name       string
	Validators []validators.BooleanValidator
	Required   bool
	Default    bool
	Errors     map[uint]string
	ErrorFunc  ErrorFunc

	AllowStrings bool // Allow pass strings "t", "true", "f", "false" as valid boolean.
	AllowNumbers bool // Allow pass numbers 0 or 1 as valid boolean.
}

Boolean is boolean field.

func (*Boolean) GetDefault

func (field *Boolean) GetDefault() interface{}

GetDefault returns the default value.

func (*Boolean) GetError

func (field *Boolean) GetError(code uint, value interface{}, parameters ...interface{}) error

GetError returns error by code.

func (*Boolean) GetName

func (field *Boolean) GetName() string

GetName returns field name.

func (*Boolean) IsRequired

func (field *Boolean) IsRequired() bool

IsRequired returns true if field is required.

func (*Boolean) Validate

func (field *Boolean) Validate(v interface{}) (interface{}, error)

Validate check and clean an input value.

type Datetime

type Datetime struct {
	Name       string
	Validators []validators.DatetimeValidator
	Required   bool
	Default    time.Time
	Errors     map[uint]string
	ErrorFunc  ErrorFunc
}

Datetime is integer field.

func (*Datetime) GetDefault

func (field *Datetime) GetDefault() interface{}

GetDefault returns the default value.

func (*Datetime) GetError

func (field *Datetime) GetError(code uint, value interface{}, parameters ...interface{}) error

GetError returns error by code.

func (*Datetime) GetName

func (field *Datetime) GetName() string

GetName returns field name.

func (*Datetime) IsRequired

func (field *Datetime) IsRequired() bool

IsRequired returns true if field is required.

func (*Datetime) Validate

func (field *Datetime) Validate(v interface{}) (interface{}, error)

Validate check and clean an input value.

type Email

type Email struct {
	Name       string
	Validators []validators.StringValidator
	Required   bool
	Default    string
	Errors     map[uint]string
	ErrorFunc  ErrorFunc
}

Email is integer field.

func (*Email) GetDefault

func (field *Email) GetDefault() interface{}

GetDefault returns the default value.

func (*Email) GetError

func (field *Email) GetError(code uint, value interface{}, parameters ...interface{}) error

GetError returns error by code.

func (*Email) GetName

func (field *Email) GetName() string

GetName returns field name.

func (*Email) IsRequired

func (field *Email) IsRequired() bool

IsRequired returns true if field is required.

func (*Email) Validate

func (field *Email) Validate(v interface{}) (interface{}, error)

Validate check and clean an input value.

type ErrorFunc

type ErrorFunc func(field Field, code uint, value interface{}, parameters ...interface{}) error

type Field

type Field interface {
	GetName() string
	IsRequired() bool
	GetDefault() interface{}
	GetError(code uint, value interface{}, parameters ...interface{}) error
	Validate(value interface{}) (interface{}, error)
}

Field describes a field interface.

type Float

type Float struct {
	Name       string
	Validators []validators.FloatValidator
	Required   bool
	Default    float64
	Errors     map[uint]string
	ErrorFunc  ErrorFunc

	AllowStrings bool
}

Float is float field.

func (*Float) GetDefault

func (field *Float) GetDefault() interface{}

GetDefault returns the default value.

func (*Float) GetError

func (field *Float) GetError(code uint, value interface{}, parameters ...interface{}) error

GetError returns error by code.

func (*Float) GetName

func (field *Float) GetName() string

GetName returns field name.

func (*Float) IsRequired

func (field *Float) IsRequired() bool

IsRequired returns true if field is required.

func (*Float) Validate

func (field *Float) Validate(v interface{}) (interface{}, error)

Validate check and clean an input value.

type Integer

type Integer struct {
	Name       string
	Validators []validators.IntegerValidator
	Required   bool
	Default    int
	Errors     map[uint]string
	ErrorFunc  ErrorFunc

	AllowStrings bool
}

Integer is integer field.

func (*Integer) GetDefault

func (field *Integer) GetDefault() interface{}

GetDefault returns the default value.

func (*Integer) GetError

func (field *Integer) GetError(code uint, value interface{}, parameters ...interface{}) error

GetError returns error by code.

func (*Integer) GetName

func (field *Integer) GetName() string

GetName returns field name.

func (*Integer) IsRequired

func (field *Integer) IsRequired() bool

IsRequired returns true if field is required.

func (*Integer) Validate

func (field *Integer) Validate(v interface{}) (interface{}, error)

Validate check and clean an input value.

type String

type String struct {
	Name       string
	Validators []validators.StringValidator
	Required   bool
	Default    string
	Errors     map[uint]string
	ErrorFunc  ErrorFunc

	AllowBlank bool
}

String is boolean field.

func (*String) GetDefault

func (field *String) GetDefault() interface{}

GetDefault returns the default value.

func (*String) GetError

func (field *String) GetError(code uint, value interface{}, parameters ...interface{}) error

GetError returns error by code.

func (*String) GetName

func (field *String) GetName() string

GetName returns field name.

func (*String) IsRequired

func (field *String) IsRequired() bool

IsRequired returns true if field is required.

func (*String) Validate

func (field *String) Validate(v interface{}) (interface{}, error)

Validate check and clean an input value.

type URL

type URL struct {
	Name       string
	Validators []validators.StringValidator
	Required   bool
	Default    float64
	Errors     map[uint]string
	ErrorFunc  ErrorFunc
}

URL is integer field.

func (*URL) GetDefault

func (field *URL) GetDefault() interface{}

GetDefault returns the default value.

func (*URL) GetError

func (field *URL) GetError(code uint, value interface{}, parameters ...interface{}) error

GetError returns error by code.

func (*URL) GetName

func (field *URL) GetName() string

GetName returns field name.

func (*URL) IsRequired

func (field *URL) IsRequired() bool

IsRequired returns true if field is required.

func (*URL) Validate

func (field *URL) Validate(v interface{}) (interface{}, error)

Validate check and clean an input value.

Jump to

Keyboard shortcuts

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