← All notes

net/url: parse URLs and escape paths

Answer: Package net/url represents a URL with scheme, host, path, query, and fragment fields. ParseRequestURI parses a raw url into a URL structure. Prefer EscapedPath over reading RawPath directly.

The URL form

The general form is [scheme:][//[userinfo@]host][/]path[?query][#fragment].

ParseRequestURI parses a raw url into a URL structure.

The Host field contains the host and port subcomponents of the URL.

If a slash does not follow the scheme, the URL is read as scheme:opaque[?query][#fragment].

A hostname and path with no scheme is invalid to parse, though ambiguities mean an error is not guaranteed.

EscapedPath, String, and Values

RawPath is optional and stores an encoded path hint.

EscapedPath returns RawPath when it is a valid escaping of Path. Otherwise it ignores RawPath and computes an escaped form on its own.

The String and RequestURI methods use EscapedPath to construct their results.

In general, call EscapedPath instead of reading u.RawPath directly.

If u.Opaque is non-empty, String uses the opaque form; otherwise it uses the host and path form.

Query parameters and form values typically go in a Values map. Those keys are case-sensitive, unlike keys in http.Header.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Go, net/url package reference; Go, net/url/url.go source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Go, net/url package reference; Go, net/url/url.go source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors.

Cite this

Permanent ID: iil:note:cfs5w7mv

iinventedlight. 2026. "net/url: parse URLs and escape paths." iinventedlight Library, iil:note:cfs5w7mv, version of 2026-11-23. https://iinventedlight.com/library/notes/go-net-url/. License: CC-BY-4.0.

@misc{iil_note_cfs5w7mv,
  author = {{iinventedlight}},
  title = {{net/url: parse URLs and escape paths}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-23},
  url = {https://iinventedlight.com/library/notes/go-net-url/},
  note = {Permanent ID iil:note:cfs5w7mv. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/go-net-url.md.