Documentation
¶
Overview ¶
Package forms contains methods for handling form decoding and encoding.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDecode indicates an error occurred during decoding. ErrDecode = errors.New("error in decoding") // ErrEncode indicates an error occurred during encoding. ErrEncode = errors.New("error in encoding") // ErrValidation indicates an error occurred during validation. ErrValidation = errors.New("validation failed") // ErrNoFormData indicates that no form data was parsed. ErrNoFormData = errors.New("no form data") // ErrSanitise indicates an error occurred during sanitisation. ErrSanitise = errors.New("sanitisation failed") // ErrFileTooLarge can be used to indicate a file upload had a size greater than a set limit. ErrFileTooLarge = errors.New("file is too large") )
Functions ¶
func DecodeForm ¶
DecodeForm will decode submitted form contents into the passed in type. It will perform validation of the type and will return the type and a boolean true if it is valid. If decoding the form submission fails, a non-nill error is returned.
func DecodeMultipartValue ¶
DecodeMultipartValue will the file represented by the given field in a multipart form submission. It will perform validation of the file and will return the file object and a boolean true if it is valid. If decoding fails, a non-nil error is returned.
Types ¶
type FileUpload ¶
type FileUpload struct {
*multipart.FileHeader `json:"header" validate:"required"`
multipart.File `json:"data" validate:"required"`
}
func DecodeMultipartFile ¶
func DecodeMultipartFile(req *http.Request, field string) (*FileUpload, error)
DecodeMultipartFile will decode the file represented by the given field in a multipart form submission. It will return the data as a FileUpload. If decoding fails, a non-nil error is returned.
func (FileUpload) GetFilename ¶
func (f FileUpload) GetFilename() string
func (FileUpload) GetHeader ¶
func (f FileUpload) GetHeader(key string) string
func (FileUpload) ParseMimetype ¶
func (f FileUpload) ParseMimetype() (string, error)
ParseMimetype attempts to parse and return the mime type of the file from its mime header.
func (FileUpload) Validate ¶
func (f FileUpload) Validate() error