formdata

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2024 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package formdata provides a way to safely and conveniently extract html Form data using a definied schema.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoValue         = errors.New("expected value to exist")
	ErrMulitpleValues  = errors.New("expected only one value to exist")
	ErrFieldNotPresent = errors.New("requested field does not exist")
	ErrParseFailure    = errors.New("could not parse value")
)

Functions

func Parse

func Parse(data url.Values, schema Schema) error

func ParseForm

func ParseForm(r *http.Request, schema Schema) error

Types

type Parser

type Parser interface {
	Parse([]string) error
}

A Parser implementation is capable of extracting a value from the value of an url.Values, which is a slice of string.

func Bool

func Bool(b *bool) Parser

Bool is used to extract a form data value into a Go bool. If the value is not a bool or is missing than an error is returned during parsing.

func BoolOr added in v0.3.3

func BoolOr(b *bool, alt bool) Parser

BoolOr is used to extract a form data value into a Go bool. If the value is missing, then the alt value is used instead.

func Float

func Float(f *float64) Parser

Float is used to extract a form data value into a Go float64. If the value is not a float or is missing then an error is returned during parsing.

func FloatOr added in v0.3.3

func FloatOr(f *float64, alt float64) Parser

FloatOr is used to extract a form data value into a Go float64. If the value is missing, then the alt value is used instead.

func Int

func Int(i *int) Parser

Int is used to extract a form data value into a Go int. If the value is not an int or is missing then an error is returned during parsing.

func IntOr added in v0.3.3

func IntOr(i *int, alt int) Parser

IntOr is used to extract a form data value into a Go int. If the value is missing, then the alt value is used instead.

func Secret added in v0.3.3

func Secret(s **conceal.Text) Parser

Secret is used to extract a form data value into a Go conceal.Text. If the value is missing then an error is returned during parsing.

func String

func String(s *string) Parser

String is used to extract a form data value into a Go string. If the value is not a string or is missing then an error is returned during parsing.

func StringOr added in v0.3.3

func StringOr(s *string, alt string) Parser

StringOr is used to extract a form data value into a Go string. If the value is missing, then the alt value is used instead.

type Schema

type Schema map[string]Parser

A Schema describes how a set of url.Values should be parsed. Typically these are coming from an http.Request.Form from inside an http.Handler responding to an inbound request.

Jump to

Keyboard shortcuts

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