form

package
v0.30.7 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package form implements application/x-www-form-urlencoded as a codec.Codec — the encoding every HTML form POSTs and every query string carries. It is stdlib-only: net/url supplies the decode half.

The wire format is a flat, ordered list of key=value pairs joined by '&', with keys and values percent-escaped and space written as '+'. It has no types, no nesting, and no array syntax: the ONLY way to carry more than one value under a key is to repeat the key. This codec models that literally, so its native Go shape is url.Values (== map[string][]string). Marshal accepts url.Values, map[string][]string and — for the common single-valued form — map[string]string, plus non-nil pointers to any of the three; Unmarshal writes into a pointer to any of the three.

Repeated keys: "a=1&a=2" decodes to {"a": ["1","2"]}, in wire order. No bracket dialect (a[]=, a[0]=) is invented and no value is dropped — see the package CLAUDE.md for the full round-trip contract and the two documented places where Marshal ∘ Unmarshal is not byte-for-byte identity.

Index

Constants

This section is empty.

Variables

View Source
var (
	//: register the singleton and expose it as a typed package var.
	Codec codec.Codec = codec.Register(&formCodec{})
)

The registered singleton. Its aliases are literals in MIMETypes and Extensions, not package tables: Register reads them through the Codec interface, which orders no table before this initialiser (see core/data/codec.Register).

Functions

func AppendPair added in v0.30.3

func AppendPair(dst []byte, key string, value []byte) []byte

AppendPair appends the one pair key=value to dst, both percent-escaped as Marshal escapes them, and returns the grown buffer. It writes exactly the bytes Marshal writes for a url.Values holding that one key and one value, but from a payload that is already bytes and without building the map: the buffer is grown once, to the exact length, so a nil dst costs one allocation. The facade's promotion of a value to Form writes its JSON through it (#910).

func New

func New() codec.Codec

New returns the urlencoded form codec instance.

Types

This section is empty.

Jump to

Keyboard shortcuts

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