forms

package
v0.71.2 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Overview

Package forms contains methods for handling form decoding and encoding.

Index

Constants

This section is empty.

Variables

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

Functions

func DecodeForm

func DecodeForm[T FormInput](req *http.Request) (T, bool, error)

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 DecodeMultiPartForm added in v0.45.0

func DecodeMultiPartForm[T FormInput](req *http.Request) (T, bool, error)

func DecodeMultipartFile

func DecodeMultipartFile(req *http.Request, field string) (*models.FileUpload, error)

DecodeMultipartFile 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-nill error is returned.

func DecodeMultipartValue

func DecodeMultipartValue(req *http.Request, field string) (string, error)

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-nill error is returned.

Types

type FileUpload

type FileUpload interface {
	Set(hdr *multipart.FileHeader, data multipart.File)
}

FileUpload represents file data uploaded through a mutlipart form.

type FormInput

type FormInput interface {
	Valid() error
	Sanitise() error
}

FormInput represents form input data. It has methods to test if the data is valid and to sanitise the input data.

Jump to

Keyboard shortcuts

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