domain

package
v0.0.0-...-17ece98 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2020 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
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

func FromCookies(cookies []*http.Cookie) map[string]string

FromCookies returns converted value from request's cookies.

func FromHeaders

func FromHeaders(headers http.Header) map[string][]string

FromHeaders returns converted value from request's headers.

func FromRequest

func FromRequest(req *http.Request) map[string][]string

FromRequest returns converted value from a request.

Types

type ID

type ID string

ID wraps built-in `string` type and provides useful methods above it.

func (ID) IsEmpty

func (s ID) IsEmpty() bool

IsEmpty returns true if the ID is empty.

func (ID) IsValid

func (s ID) IsValid() bool

IsValid returns true if the ID is not empty and compatible with RFC 4122.

func (ID) String

func (s ID) String() string

String implements built-in `fmt.Stringer` interface and returns the underlying string value.

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

func (v Input) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Input) MarshalJSON

func (v Input) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Input) UnmarshalEasyJSON

func (v *Input) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Input) UnmarshalJSON

func (v *Input) UnmarshalJSON(data []byte) error

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) Option

func (context InputContext) Option() Option

Option TODO issue#173

func (InputContext) Referer

func (context InputContext) Referer() string

Referer TODO issue#173

func (InputContext) Request

func (context InputContext) Request() *ID

Request TODO issue#173

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 InputData

type InputData url.Values

InputData TODO issue#173

func (InputData) Redirect

func (d InputData) Redirect(fallback ...string) string

Redirect TODO issue#173

func (InputData) Resource

func (d InputData) Resource() ID

Resource TODO issue#173

func (InputData) Template

func (d InputData) Template() *ID

Template TODO issue#173

func (InputData) Timeout

func (d InputData) Timeout() time.Duration

Timeout 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) Redirect

func (event InputEvent) Redirect() string

Redirect TODO issue#173

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

func (v Option) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Option) MarshalJSON

func (v Option) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (*Option) UnmarshalEasyJSON

func (v *Option) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Option) UnmarshalJSON

func (v *Option) UnmarshalJSON(data []byte) error

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

func (s *Schema) Apply(data map[string][]string) (map[string][]string, ValidationError)

Apply uses filtration, normalization, and validation for input values. It can raise the panic if the input type is unsupported.

func (*Schema) Filter

func (s *Schema) Filter(data map[string][]string) map[string][]string

Filter applies the schema to input values to remove unspecified from them.

func (*Schema) Input

func (s *Schema) Input(name string) *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) IsEmpty

func (s *Schema) IsEmpty() bool

IsEmpty TODO issue#173

func (Schema) MarshalEasyJSON

func (v Schema) MarshalEasyJSON(w *jwriter.Writer)

MarshalEasyJSON supports easyjson.Marshaler interface

func (Schema) MarshalHTML

func (s Schema) MarshalHTML() ([]byte, error)

MarshalHTML encodes the schema to HTML by default template.

func (Schema) MarshalJSON

func (v Schema) MarshalJSON() ([]byte, error)

MarshalJSON supports json.Marshaler interface

func (Schema) MarshalXML

func (s Schema) MarshalXML(e *xml.Encoder, start xml.StartElement) error

MarshalXML implements built-in `encoding/xml.Marshaler` interface.

func (*Schema) Normalize

func (s *Schema) Normalize(data map[string][]string) map[string][]string

Normalize removes unnecessary characters from input values. TODO move to InputData

func (*Schema) UnmarshalEasyJSON

func (v *Schema) UnmarshalEasyJSON(l *jlexer.Lexer)

UnmarshalEasyJSON supports easyjson.Unmarshaler interface

func (*Schema) UnmarshalJSON

func (v *Schema) UnmarshalJSON(data []byte) error

UnmarshalJSON supports json.Unmarshaler interface

func (*Schema) Validate

func (s *Schema) Validate(data map[string][]string) (map[string][]string, ValidationError)

Validate checks input values for errors. It can raise the panic if the input type is unsupported. TODO use InputData

type Template

type Template string

Template TODO issue#173

func (Template) IsEmpty

func (t Template) IsEmpty() bool

IsEmpty TODO issue#173

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.

func Validate

func Validate(inputs []Input, rules map[string][]Validator, data map[string][]string) ValidationError

Validate gets input metadata, validation rules and checks the input data.

type Validator

type Validator interface {
	// Validate validates the input values.
	Validate(values []string) error
}

Validator defines the basic behavior of input validators.

type ValidatorFunc

type ValidatorFunc func(values []string) error

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).

Jump to

Keyboard shortcuts

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