form

package
v0.19.5 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 3 Imported by: 0

README

form

import "github.com/kitsunium/sdk/pkg/v1/data/codec/form"

Package form registers the application/x-www-form-urlencoded codec with the SDK's codec registry — and no other codec — when it is imported (ADR 0134):

import _ "github.com/kitsunium/sdk/pkg/v1/data/codec/form"

The codec reads and writes the encoding every HTML form posts. Its native value is url.Values — map[string][]string and map[string]string are accepted too — because a repeated key is the only array syntax the format has: a body repeating a key decoded into a map[string]string is refused rather than reduced to one value. Through the codec package's Marshal any other value is carried as one JSON-mediated field.

Everything that dispatches through the registry by format name then reads and writes it: the codec package's Marshal and Unmarshal, config.FSSource and i18n.LoadFS. Importing github.com/kitsunium/sdk/pkg/v1/data/codec instead registers every format the SDK ships; this package links this one codec, the core package declaring its codes and the standard library, and nothing else. Importing both is harmless: a format is registered by the package that implements it, which Go initialises once however many packages import it.

Errors

Failures carry the range 0.3.40.*; match them with errs.HasCode, or the sentinels with errors.Is:

CodeValueInvalid     0.3.40.1  the value or the target is not url.Values-shaped
CodeUnmarshalFailed  0.3.40.2  a malformed escape, a ';' separator, or a decode bound exceeded
CodeMultiValue       0.3.40.3  a repeated key decoded into a map[string]string

There is no marshal failure: past the shape check, percent-escaping a map of strings cannot fail.

No error message quotes the input.

Index

Constants

const CodeMultiValue errs.Code = 206851

CodeMultiValue is 0.3.40.3: a repeated key decoded into a map[string]string.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/form.CodeFormMultiValue.

Code 0.3.40.3

const CodeUnmarshalFailed errs.Code = 206850

CodeUnmarshalFailed is 0.3.40.2: a malformed escape, a ';' separator, or a decode bound exceeded.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/form.CodeFormUnmarshalFailed.

Code 0.3.40.2

const CodeValueInvalid errs.Code = 206849

CodeValueInvalid is 0.3.40.1: the value or the target is not url.Values-shaped.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/form.CodeFormValueInvalid.

Code 0.3.40.1

const Format = "form"

Format is the name the urlencoded form is registered under. It is an untyped constant, so it goes wherever a format name is taken — the codec package's Marshal, config.FSSource's string, i18n.LoadFS's codec.Format — without a conversion.

Variables

var MultiValue *errs.Error

MultiValue is the sentinel of CodeMultiValue.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/form.MultiValue.

Code 0.3.40.3 · reason MULTI_VALUE · public "form key carries multiple values"

var UnmarshalFailed *errs.Error

UnmarshalFailed is the sentinel of CodeUnmarshalFailed.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/form.UnmarshalFailed.

Code 0.3.40.2 · reason UNMARSHAL_FAILED · public "form decoding failed"

var ValueInvalid *errs.Error

ValueInvalid is the sentinel of CodeValueInvalid.

Initialised with github.com/kitsunium/sdk/internal/core/data/codec/form.ValueInvalid.

Code 0.3.40.1 · reason VALUE_INVALID · public "form codec requires a url.Values-shaped value"

Generated from docs/api by tools/genindex.

Documentation

Overview

Package form registers the application/x-www-form-urlencoded codec with the SDK's codec registry — and no other codec — when it is imported (ADR 0134):

import _ "github.com/kitsunium/sdk/pkg/v1/data/codec/form"

The codec reads and writes the encoding every HTML form posts. Its native value is url.Values — map[string][]string and map[string]string are accepted too — because a repeated key is the only array syntax the format has: a body repeating a key decoded into a map[string]string is refused rather than reduced to one value. Through the codec package's Marshal any other value is carried as one JSON-mediated field.

Everything that dispatches through the registry by format name then reads and writes it: the codec package's Marshal and Unmarshal, config.FSSource and i18n.LoadFS. Importing github.com/kitsunium/sdk/pkg/v1/data/codec instead registers every format the SDK ships; this package links this one codec, the core package declaring its codes and the standard library, and nothing else. Importing both is harmless: a format is registered by the package that implements it, which Go initialises once however many packages import it.

Errors

Failures carry the range 0.3.40.*; match them with errs.HasCode, or the sentinels with errors.Is:

CodeValueInvalid     0.3.40.1  the value or the target is not url.Values-shaped
CodeUnmarshalFailed  0.3.40.2  a malformed escape, a ';' separator, or a decode bound exceeded
CodeMultiValue       0.3.40.3  a repeated key decoded into a map[string]string

There is no marshal failure: past the shape check, percent-escaping a map of strings cannot fail.

No error message quotes the input.

Index

Constants

View Source
const (
	// CodeValueInvalid is 0.3.40.1: the value or the target is not
	// url.Values-shaped.
	CodeValueInvalid errs.Code = coreform.CodeFormValueInvalid
	// CodeUnmarshalFailed is 0.3.40.2: a malformed escape, a ';' separator, or
	// a decode bound exceeded.
	CodeUnmarshalFailed errs.Code = coreform.CodeFormUnmarshalFailed
	// CodeMultiValue is 0.3.40.3: a repeated key decoded into a
	// map[string]string.
	CodeMultiValue errs.Code = coreform.CodeFormMultiValue
)

The error codes, range 0.3.40.*, declared in the core (ADR 0160).

View Source
const Format = "form"

Format is the name the urlencoded form is registered under. It is an untyped constant, so it goes wherever a format name is taken — the codec package's Marshal, config.FSSource's string, i18n.LoadFS's codec.Format — without a conversion.

Variables

View Source
var (
	// ValueInvalid is the sentinel of [CodeValueInvalid].
	ValueInvalid = coreform.ValueInvalid
	// UnmarshalFailed is the sentinel of [CodeUnmarshalFailed].
	UnmarshalFailed = coreform.UnmarshalFailed
	// MultiValue is the sentinel of [CodeMultiValue].
	MultiValue = coreform.MultiValue
)

The sentinels, for errors.Is: each carries the code of the same name.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

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