Documentation
¶
Index ¶
- Constants
- func FromCookies(cookies []*http.Cookie) map[string]string
- func FromHeaders(headers http.Header) map[string][]string
- func FromRequest(req *http.Request) map[string][]string
- type ID
- type Input
- type InputContext
- func (context InputContext) Header(key string) string
- func (context InputContext) Identifier() *ID
- func (v InputContext) MarshalEasyJSON(w *jwriter.Writer)
- func (v InputContext) MarshalJSON() ([]byte, error)
- func (context InputContext) Option() Option
- func (context InputContext) Referer() string
- func (context InputContext) Request() *ID
- func (v *InputContext) UnmarshalEasyJSON(l *jlexer.Lexer)
- func (v *InputContext) UnmarshalJSON(data []byte) error
- func (context InputContext) UserAgent() string
- type InputData
- type InputEvent
- type Option
- type Schema
- func (s *Schema) Apply(data map[string][]string) (map[string][]string, ValidationError)
- func (s *Schema) Filter(data map[string][]string) map[string][]string
- func (s *Schema) Input(name string) *Input
- func (s *Schema) IsEmpty() bool
- func (v Schema) MarshalEasyJSON(w *jwriter.Writer)
- func (s Schema) MarshalHTML() ([]byte, error)
- func (v Schema) MarshalJSON() ([]byte, error)
- func (s Schema) MarshalXML(e *xml.Encoder, start xml.StartElement) error
- func (s *Schema) Normalize(data map[string][]string) map[string][]string
- func (v *Schema) UnmarshalEasyJSON(l *jlexer.Lexer)
- func (v *Schema) UnmarshalJSON(data []byte) error
- func (s *Schema) Validate(data map[string][]string) (map[string][]string, ValidationError)
- type Template
- type ValidationError
- type Validator
- type ValidatorFunc
Constants ¶
const ( // EmailType specifies `<input type="email">`. EmailType = "email" // HiddenType specifies `<input type="hidden">` HiddenType = "hidden" // TextType specifies `<input type="text">`. TextType = "text" )
Variables ¶
This section is empty.
Functions ¶
func FromCookies ¶
FromCookies returns converted value from request's cookies.
func FromHeaders ¶
FromHeaders returns converted value from request's headers.
Types ¶
type ID ¶
type ID string
ID wraps built-in `string` type and provides useful methods above it.
type Input ¶
type Input struct { ID string `json:"id,omitempty" yaml:"id,omitempty" xml:"id,attr,omitempty"` Name string `json:"name" yaml:"name" xml:"name,attr"` Type string `json:"type" yaml:"type" xml:"type,attr"` Title string `json:"title,omitempty" yaml:"title,omitempty" xml:"title,attr,omitempty"` Placeholder string `json:"placeholder,omitempty" yaml:"placeholder,omitempty" xml:"placeholder,attr,omitempty"` Value string `json:"value,omitempty" yaml:"value,omitempty" xml:"value,attr,omitempty"` MinLength int `json:"minlength,omitempty" yaml:"minlength,omitempty" xml:"minlength,attr,omitempty"` MaxLength int `json:"maxlength,omitempty" yaml:"maxlength,omitempty" xml:"maxlength,attr,omitempty"` Required bool `json:"required,omitempty" yaml:"required,omitempty" xml:"required,attr,omitempty"` Strict bool `json:"strict,omitempty" yaml:"strict,omitempty" xml:"strict,attr,omitempty"` }
Input represents an element of an HTML form.
func (Input) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (Input) MarshalJSON ¶
MarshalJSON supports json.Marshaler interface
func (*Input) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Input) UnmarshalJSON ¶
UnmarshalJSON supports json.Unmarshaler interface
type InputContext ¶
type InputContext struct { Cookies map[string]string `json:"cookies,omitempty"` Headers map[string][]string `json:"headers,omitempty"` Queries map[string][]string `json:"queries,omitempty"` }
InputContext contains context information about an input event.
func (InputContext) Header ¶
func (context InputContext) Header(key string) string
Header TODO issue#173
func (InputContext) Identifier ¶
func (context InputContext) Identifier() *ID
Identifier TODO issue#173
func (InputContext) MarshalEasyJSON ¶
func (v InputContext) MarshalEasyJSON(w *jwriter.Writer)
MarshalEasyJSON supports easyjson.Marshaler interface
func (InputContext) MarshalJSON ¶
func (v InputContext) MarshalJSON() ([]byte, error)
MarshalJSON supports json.Marshaler interface
func (*InputContext) UnmarshalEasyJSON ¶
func (v *InputContext) UnmarshalEasyJSON(l *jlexer.Lexer)
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*InputContext) UnmarshalJSON ¶
func (v *InputContext) UnmarshalJSON(data []byte) error
UnmarshalJSON supports json.Unmarshaler interface
func (InputContext) UserAgent ¶
func (context InputContext) UserAgent() string
UserAgent TODO issue#173
type InputEvent ¶
type InputEvent struct { SchemaID ID `json:"schema_id"` InputID ID `json:"input_id"` TemplateID *ID `json:"template_id,omitempty"` Identifier *ID `json:"identifier,omitempty"` Context InputContext `json:"context"` Code int `json:"code"` URL string `json:"url"` }
InputEvent TODO issue#173
func (InputEvent) MarshalEasyJSON ¶
func (v InputEvent) MarshalEasyJSON(w *jwriter.Writer)
MarshalEasyJSON supports easyjson.Marshaler interface
func (InputEvent) MarshalJSON ¶
func (v InputEvent) MarshalJSON() ([]byte, error)
MarshalJSON supports json.Marshaler interface
func (*InputEvent) UnmarshalEasyJSON ¶
func (v *InputEvent) UnmarshalEasyJSON(l *jlexer.Lexer)
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*InputEvent) UnmarshalJSON ¶
func (v *InputEvent) UnmarshalJSON(data []byte) error
UnmarshalJSON supports json.Unmarshaler interface
type Option ¶
type Option struct { // Anonymously: use zero-identifier instead of origin. Anonymously bool // Debug: return debug information to the client. Debug bool // NoLog: do not log link navigation. NoLog bool }
Option contains rules for request processing.
func (Option) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (Option) MarshalJSON ¶
MarshalJSON supports json.Marshaler interface
func (*Option) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Option) UnmarshalJSON ¶
UnmarshalJSON supports json.Unmarshaler interface
type Schema ¶
type Schema struct { ID string `json:"id,omitempty" yaml:"id,omitempty" xml:"id,attr,omitempty"` Language string `json:"lang,omitempty" yaml:"lang,omitempty" xml:"lang,attr,omitempty"` Title string `json:"title,omitempty" yaml:"title,omitempty" xml:"title,attr,omitempty"` Action string `json:"action,omitempty" yaml:"action,omitempty" xml:"action,attr,omitempty"` Method string `json:"method,omitempty" yaml:"method,omitempty" xml:"method,attr,omitempty"` EncodingType string `json:"enctype,omitempty" yaml:"enctype,omitempty" xml:"enctype,attr,omitempty"` Inputs []Input `json:"input" yaml:"input" xml:"input"` }
Schema represents an HTML form.
func (*Schema) Apply ¶
Apply uses filtration, normalization, and validation for input values. It can raise the panic if the input type is unsupported.
func (*Schema) Input ¶
Input searches an Input by its name in a case-insensitive manner and returns it or nil if can't find it. Useful in templates:
{{ with .Schema.Input "email" }} {{ template "input" . }} {{ end }}
func (Schema) MarshalEasyJSON ¶
MarshalEasyJSON supports easyjson.Marshaler interface
func (Schema) MarshalHTML ¶
MarshalHTML encodes the schema to HTML by default template.
func (Schema) MarshalJSON ¶
MarshalJSON supports json.Marshaler interface
func (Schema) MarshalXML ¶
MarshalXML implements built-in `encoding/xml.Marshaler` interface.
func (*Schema) Normalize ¶
Normalize removes unnecessary characters from input values. TODO move to InputData
func (*Schema) UnmarshalEasyJSON ¶
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*Schema) UnmarshalJSON ¶
UnmarshalJSON supports json.Unmarshaler interface
type ValidationError ¶
type ValidationError interface { error // HasError returns true if the input value has at least one error. HasError(input Input) bool // InputWithErrors returns a map of form inputs with at least one error and their errors. InputWithErrors() map[Input][]error }
ValidationError defines the behavior of error related to invalid input values.
type Validator ¶
type Validator interface { // Validate validates the input values. Validate(values []string) error }
Validator defines the basic behavior of input validators.
type ValidatorFunc ¶
ValidatorFunc type is an adapter to allow the use of ordinary functions as a validator.
func LengthValidator ¶
func LengthValidator(min, max int) ValidatorFunc
LengthValidator returns the validator to check an input value length.
func RequireValidator ¶
func RequireValidator() ValidatorFunc
RequireValidator returns the validator to check an input value for a not-empty.
func TypeValidator ¶
func TypeValidator(inputType string, strict bool) ValidatorFunc
TypeValidator returns the validator to check an input value for compliance the type. It can raise the panic if the input type is unsupported.
func (ValidatorFunc) Validate ¶
func (fn ValidatorFunc) Validate(values []string) error
Validate calls fn(values).