forms

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 1, 2019 License: MIT Imports: 5 Imported by: 0

README

govenant/forms

Form handling and data validation for Go

Installation

go get -u github.com/govenant/forms

Usage

See examples

Changelog

See releases

License

See LICENSE

Documentation

Index

Constants

View Source
const (
	Unknown uint = iota
	InvalidJSON
	Required
	Invalid
)

Variables

View Source
var Messages = map[uint]string{
	Unknown:     "Unknown error.",
	Invalid:     "Ensure that all values are valid.",
	InvalidJSON: "Unable to parse JSON.",
	Required:    "Value is required.",
}

Functions

func Validate

func Validate(form Form, data Data) error

func ValidateForm

func ValidateForm(form Form, data url.Values) error

func ValidateJSON

func ValidateJSON(form Form, reader io.Reader) error

func ValidateMultipartForm

func ValidateMultipartForm(form Form, data *multipart.Form) error

Types

type BaseForm

type BaseForm struct{}

func (*BaseForm) Clean

func (form *BaseForm) Clean(_ Data) error

func (*BaseForm) FieldError

func (form *BaseForm) FieldError(field string, code uint, parameters ...interface{}) error

func (*BaseForm) FormError

func (form *BaseForm) FormError(code uint, errors ...error) error

func (*BaseForm) Messages

func (form *BaseForm) Messages() map[uint]string

func (*BaseForm) OnError

func (form *BaseForm) OnError(err *FormError) error

func (*BaseForm) Schema

func (form *BaseForm) Schema() Schema

type Clean

type Clean func(data Data) error

type Data

type Data interface {
	Get(key string) interface{}
	GetAll(key string) interface{}
}

type FieldError

type FieldError struct {
	Code       uint          `json:"code"`
	Field      string        `json:"field"`
	Message    string        `json:"message"`
	Parameters []interface{} `json:"parameters"`
}

func NewFieldError

func NewFieldError(code uint, field, message string, parameters []interface{}) *FieldError

func (*FieldError) Error

func (err *FieldError) Error() string

func (*FieldError) Format

func (err *FieldError) Format() string

type Form

type Form interface {
	Schema() Schema
	Messages() map[uint]string
	FieldError(field string, code uint, parameters ...interface{}) error
	FormError(code uint, errors ...error) error
	Clean(data Data) error
	OnError(err *FormError) error
}

type FormData

type FormData url.Values

func (FormData) Get

func (data FormData) Get(name string) interface{}

func (FormData) GetAll

func (data FormData) GetAll(name string) interface{}

type FormError

type FormError struct {
	Code    uint    `json:"code"`
	Message string  `json:"message"`
	Errors  []error `json:"errors"`
}

func NewFormError

func NewFormError(code uint, message string, errors ...error) *FormError

func (*FormError) Error

func (err *FormError) Error() string

type JSON

type JSON map[string]interface{}

func (JSON) Get

func (data JSON) Get(name string) interface{}

func (JSON) GetAll

func (data JSON) GetAll(name string) interface{}

type MultipartFormData

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

func (MultipartFormData) Get

func (data MultipartFormData) Get(name string) interface{}

func (MultipartFormData) GetAll

func (data MultipartFormData) GetAll(name string) interface{}

type Schema

type Schema []Clean

type Value

type Value struct {
	Value interface{}
}

func (Value) Get

func (value Value) Get(name string) interface{}

func (Value) GetAll

func (value Value) GetAll(name string) interface{}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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