forms

package
v0.0.0-...-b1aaf46 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: AGPL-3.0 Imports: 5 Imported by: 2

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, 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

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

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 FormInput

type FormInput interface {
	Validate() 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