Documentation ¶
Index ¶
- Constants
- func CSRFFormFieldGenerator(g CSRFGenerator) func(r *http.Request) *Field
- type CSRFGenerator
- type CSRFSetter
- type Error
- type ErrorParser
- type Field
- type FieldSetter
- type FieldSorter
- type Fields
- type HTMLForm
- func NewHTMLForm(action string) *HTMLForm
- func NewHTMLFormFromJSON(action string, raw json.RawMessage, prefix string) *HTMLForm
- func NewHTMLFormFromJSONSchema(action, jsonSchemaRef, prefix string) (*HTMLForm, error)
- func NewHTMLFormFromRequestBody(r *http.Request, action string, compiler decoderx.HTTPDecoderOption) (*HTMLForm, error)
- func (c *HTMLForm) AddError(err *Error, names ...string)
- func (c *HTMLForm) ParseError(err error) error
- func (c *HTMLForm) Reset()
- func (c *HTMLForm) Scan(value interface{}) error
- func (c *HTMLForm) SetCSRF(token string)
- func (c *HTMLForm) SetField(oldName string, field Field)
- func (c *HTMLForm) SetRequired(fields ...string)
- func (c *HTMLForm) SetValue(name string, value interface{})
- func (c *HTMLForm) SetValues(values map[string]interface{})
- func (c *HTMLForm) SortFields(schemaRef, prefix string) error
- func (c *HTMLForm) Unset(name string)
- func (c *HTMLForm) Value() (driver.Value, error)
- type Resetter
- type ValueSetter
Constants ¶
const CSRFTokenName = "csrf_token"
Variables ¶
This section is empty.
Functions ¶
func CSRFFormFieldGenerator ¶
func CSRFFormFieldGenerator(g CSRFGenerator) func(r *http.Request) *Field
Types ¶
type CSRFGenerator ¶
type CSRFSetter ¶
type CSRFSetter interface { // SetCSRF sets the CSRF value for the form. SetCSRF(string) }
type Error ¶
type Error struct { // Code FormErrorCode `json:"id,omitempty"` Message string `json:"message"` }
swagger:model formError
type ErrorParser ¶
type ErrorParser interface { // ParseError type asserts the given error and sets the forms's errors or a // field's errors and if the error is not something to be handled by the // form itself, the error is returned for further propagation (e.g. showing a 502 status code). ParseError(err error) error }
ErrorParser is capable of parsing and processing errors.
type Field ¶
type Field struct { // Name is the equivalent of <input name="{{.Name}}"> Name string `json:"name"` // Type is the equivalent of <input type="{{.Type}}"> Type string `json:"type,omitempty"` // Required is the equivalent of <input required="{{.Required}}"> Required bool `json:"required,omitempty"` // Value is the equivalent of <input value="{{.Value}}"> Value interface{} `json:"value,omitempty" faker:"name"` // Errors contains all validation errors this particular field has caused. Errors []Error `json:"errors,omitempty"` }
Field represents a HTML Form Field
swagger:model formField
type FieldSetter ¶
type FieldSorter ¶
type HTMLForm ¶
type HTMLForm struct { sync.RWMutex // Action should be used as the form action URL (<form action="{{ .Action }}" method="post">). Action string `json:"action"` // Method is the form method (e.g. POST) Method string `json:"method"` // Fields contains the form fields. Fields Fields `json:"fields"` // Errors contains all form errors. These will be duplicates of the individual field errors. Errors []Error `json:"errors,omitempty"` }
HTMLForm represents a HTML Form. The container can work with both HTTP Form and JSON requests
swagger:model form
func NewHTMLForm ¶
NewHTMLForm returns an empty container.
func NewHTMLFormFromJSON ¶
func NewHTMLFormFromJSON(action string, raw json.RawMessage, prefix string) *HTMLForm
NewHTMLFormFromJSON creates a HTML form based on the provided JSON struct.
func NewHTMLFormFromJSONSchema ¶
NewHTMLFormFromJSONSchema creates a new HTMLForm and populates the fields using the provided JSON Schema.
func NewHTMLFormFromRequestBody ¶
func NewHTMLFormFromRequestBody(r *http.Request, action string, compiler decoderx.HTTPDecoderOption) (*HTMLForm, error)
NewHTMLFormFromRequestBody creates a new HTMLForm and populates fields by parsing the HTTP Request body. A jsonSchemaRef needs to be added to allow HTTP Form Post Body parsing.
func (*HTMLForm) AddError ¶
AddError adds the provided error, and if a non-empty names list is set, adds the error on the corresponding field.
func (*HTMLForm) ParseError ¶
ParseError type asserts the given error and sets the container's errors or a field's errors and if the error is not something to be handled by the form container, the error is returned.
This method DOES NOT touch the values of the form fields, only its errors.
func (*HTMLForm) Reset ¶
func (c *HTMLForm) Reset()
Reset resets the container's errors as well as each field's value and errors.
func (*HTMLForm) SetRequired ¶
SetRequired sets the container's fields required.
func (*HTMLForm) SortFields ¶
type ValueSetter ¶
type ValueSetter interface { // SetValue sets a value of the form. SetValue(name string, value interface{}) }