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.
Package form — range 0.3.40.* (ADR 0005 service/codec/form block).
Package form — declares the sentinel *errs.Error values for the application/x-www-form-urlencoded codec.
There is deliberately no MarshalFailed sentinel: once asValues has accepted the argument shape, percent-escaping a map of strings is a total function — no byte sequence can make it fail. Defining an unreachable sentinel would put a code in the registry that no test can ever provoke.
Index ¶
Constants ¶
const CodeFormMultiValue errs.Code = 0x00_03_28_03 // 0.3.40.3
CodeFormMultiValue identifies a decode into a single-valued target (map[string]string) of a body that repeats a key — the one case where the requested Go shape cannot hold what the wire carries.
const CodeFormUnmarshalFailed errs.Code = 0x00_03_28_02 // 0.3.40.2
CodeFormUnmarshalFailed identifies a decode refusal: a malformed percent-escape, the ';' separator net/url rejects since Go 1.17, or an input that trips one of the package's decode bounds.
const CodeFormValueInvalid errs.Code = 0x00_03_28_01 // 0.3.40.1
CodeFormValueInvalid identifies a Marshal / Append / Unmarshal call whose argument is not one of the shapes the urlencoded wire format models (url.Values, map[string][]string, map[string]string, or a pointer to one).
Variables ¶
var ( // ValueInvalid fires when the caller does not pass a urlencoded-shaped // value (url.Values / map[string][]string / map[string]string, or a // non-nil pointer to one). ValueInvalid = errs.Define(CodeFormValueInvalid, "VALUE_INVALID", "form codec requires a url.Values-shaped value", "service/codec/form: Marshal/Append/Unmarshal called with an unsupported argument shape") // UnmarshalFailed wraps a refusal from net/url.ParseQuery or a decode // bound (maxFormBytes / maxFormPairs). UnmarshalFailed = errs.Define(CodeFormUnmarshalFailed, "UNMARSHAL_FAILED", "form decoding failed", "service/codec/form: net/url.ParseQuery returned an error or a decode bound was exceeded") // MultiValue fires when a repeated key is decoded into a map[string]string // target, which can hold exactly one value per key. MultiValue = errs.Define(CodeFormMultiValue, "MULTI_VALUE", "form key carries multiple values", "service/codec/form: map[string]string target cannot hold a repeated key") )
var ( //: register the singleton and expose it as a typed package var. Codec codec.Codec = codec.Register(&formCodec{}) )
Package-level state: the codec singleton plus the hoisted MIME / extension tables.
Functions ¶
Types ¶
This section is empty.