fields

package
v0.0.1-rc.0 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2017 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

BooleanErrors is a code-error mapping for Boolean field.

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

DatetimeErrors is a code-error mapping for Datetime field.

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

EmailErrors is a code-error mapping for Email field.

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

FloatErrors is a code-error mapping for Float field.

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

IntegerErrors is a code-error mapping for Integer field.

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

StringErrors is a code-error mapping for String field.

View Source
var URLErrors = map[string]string{
	"Required": "This field is required.",
	"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.Validator
	Required   bool
	Default    bool
	Errors     map[string]string

	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 string, parameters ...interface{}) error

GetError returns error by code.

func (*Boolean) GetName

func (field *Boolean) GetName() string

GetName returns field name.

func (*Boolean) GetValidators

func (field *Boolean) GetValidators() []validators.Validator

GetValidators returns additional field validators.

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.Validator
	Required   bool
	Default    float64
	Errors     map[string]string // Overrides default errors
}

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 string, parameters ...interface{}) error

GetError returns error by code.

func (*Datetime) GetName

func (field *Datetime) GetName() string

GetName returns field name.

func (*Datetime) GetValidators

func (field *Datetime) GetValidators() []validators.Validator

GetValidators returns additional field validators.

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.Validator
	Required   bool
	Default    float64
	Errors     map[string]string // Overrides default errors
}

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 string, parameters ...interface{}) error

GetError returns error by code.

func (*Email) GetName

func (field *Email) GetName() string

GetName returns field name.

func (*Email) GetValidators

func (field *Email) GetValidators() []validators.Validator

GetValidators returns additional field validators.

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 Field

type Field interface {
	GetName() string
	GetValidators() []validators.Validator
	IsRequired() bool
	GetDefault() interface{}
	GetError(code string, parameters ...interface{}) error
	Validate(value interface{}) (interface{}, error)
}

Field describes a field interface.

type Float

type Float struct {
	Name       string
	Validators []validators.Validator
	Required   bool
	Default    float64
	Errors     map[string]string // Overrides default errors

	AllowStrings bool
	MinValue     *validators.MinValueValidator
	MaxValue     *validators.MaxValueValidator
}

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 string, parameters ...interface{}) error

GetError returns error by code.

func (*Float) GetName

func (field *Float) GetName() string

GetName returns field name.

func (*Float) GetValidators

func (field *Float) GetValidators() []validators.Validator

GetValidators returns additional field validators.

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.Validator
	Required   bool
	Default    int
	Errors     map[string]string // Overrides default errors

	AllowStrings bool
	MinValue     *validators.MinValueValidator
	MaxValue     *validators.MaxValueValidator
}

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 string, parameters ...interface{}) error

GetError returns error by code.

func (*Integer) GetName

func (field *Integer) GetName() string

GetName returns field name.

func (*Integer) GetValidators

func (field *Integer) GetValidators() []validators.Validator

GetValidators returns additional field validators.

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.Validator
	Required   bool
	Default    string
	Errors     map[string]string

	AllowBlank bool
	MinLength  *validators.MinLengthValidator
	MaxLength  *validators.MaxLengthValidator
}

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 string, parameters ...interface{}) error

GetError returns error by code.

func (*String) GetName

func (field *String) GetName() string

GetName returns field name.

func (*String) GetValidators

func (field *String) GetValidators() []validators.Validator

GetValidators returns additional field validators.

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.Validator
	Required   bool
	Default    float64
	Errors     map[string]string // Overrides default errors
}

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 string, parameters ...interface{}) error

GetError returns error by code.

func (*URL) GetName

func (field *URL) GetName() string

GetName returns field name.

func (*URL) GetValidators

func (field *URL) GetValidators() []validators.Validator

GetValidators returns additional field validators.

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