Help us shape the future of Go! Take the 2026 Go Developer Survey

httpquery

package
v0.6.0 Latest Latest
Warning

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

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

Documentation

Overview

Package httpquery owns bounded query-string parsing and URL generation. It does not bind fields or interpret scalar values; those belong to typed HTTP declarations. Query text uses net/url's form escaping, not path escaping.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

func Encode(ctx context.Context, values url.Values, limits Limits) (string, error)

Encode returns a query without a leading question mark. Keys are sorted and each key's value order is preserved, matching url.Values.Encode. Nil and empty value slices omit that key. Every failure returns an empty string.

Input must remain unchanged until return. Native lengths and pair counts are checked before UTF-8 inspection or escaping. Escaping one component may use up to three times its native byte length; retained output never exceeds Bytes.

func Parse

func Parse(ctx context.Context, raw string, limits Limits) (url.Values, error)

Parse accepts a raw query without its leading question mark. It preserves repeated values and distinguishes an omitted key from a present empty value. As with net/url, a bare key has an empty value and empty slots are ignored. Invalid escapes, unescaped semicolons and invalid UTF-8 reject the entire query. Names and values never appear in error messages.

Bytes and Pairs are checked before allocating decoded strings or containers. Decoded strings may share immutable input storage. Typed bindings decide whether a repeated key, unknown name, empty value or control character is valid.

func ValidName

func ValidName(name string) bool

ValidName is the shared declaration grammar for runtime and generation. Brackets and dots are literal query-name characters, not nesting instructions.

Types

type Limits

type Limits struct {
	Bytes int
	Pairs int
}

Limits bounds encoded bytes and parameter slots. During parsing an empty slot between ampersands still counts toward Pairs. During encoding Pairs also bounds the number of map keys, including keys with no values.

func (Limits) Validate

func (l Limits) Validate() error

Jump to

Keyboard shortcuts

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