url

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Overview

Package url is the "encoding/url" host module. See std/encoding/register.go for why this and its eight siblings each get their own leaf package instead of living in std's flat root, and how this directory's Module reaches the rest of magus without std importing back down to collect it.

Index

Constants

This section is empty.

Variables

View Source
var Module = std.Module{
	Name: "url",
	WASM: true,
	Path: "encoding/url",
	Doc:  "URL percent-encoding, parsing, and building.",
	Methods: []std.Method{
		{
			Name:    "encode",
			Doc:     "Percent-encode s for use in a URL query component.",
			Args:    []std.Arg{{Name: "s", Type: std.TypeString}},
			Returns: []std.Ret{{Type: std.TypeString}},
			Impl:    URLEncode,
		},
		{
			Name:    "decode",
			Doc:     "Decode a percent-encoded URL query component; errors on malformed input.",
			Args:    []std.Arg{{Name: "s", Type: std.TypeString}},
			Returns: []std.Ret{{Type: std.TypeString}},
			Raises:  true,
			Impl:    URLDecode,
		},
		{
			Name:    "parse",
			Doc:     "Parse a URL string into {scheme, host, port, path, query, fragment}; errors on malformed input.",
			Args:    []std.Arg{{Name: "raw_url", Type: std.TypeString}},
			Returns: []std.Ret{{Type: std.TypeAnyMap, Object: "URL"}},
			Raises:  true,
			Impl:    URLParse,
		},
		{
			Name:    "build",
			Doc:     "Build a URL string from a URL object - the same shape parse returns, so the two round-trip. Missing fields are treated as empty.",
			Args:    []std.Arg{{Name: "parts", Type: std.TypeAnyMap, Object: "URL"}},
			Returns: []std.Ret{{Type: std.TypeString}},
			Impl:    URLBuild,
		},
	},
}

Module is the "encoding/url" host module: percent-encoding, plus parsing a URL into its components and building one back out.

Filed under encoding/ rather than Go's net/url because percent-encoding IS a text codec and belongs beside base64 and hex, and because magus has no net/ tree for a single module to justify. parse and build round-trip through the same URL object, so a caller can take a URL apart, change one field, and put it back without string surgery on a query string.

Functions

func Modules

func Modules() []std.Module

Modules returns this directory's contribution to the encoding module set. See std/encoding/register.go: it aggregates every leaf's Modules() into one slice, which is how a module here reaches std.All()'s callers without std importing this package to collect it.

func URLBuild

func URLBuild(_ context.Context, parts map[string]any) (string, error)

URLBuild assembles a URL string from a parts map with keys scheme, host, port, path, query, fragment. Missing keys are treated as empty.

func URLDecode

func URLDecode(_ context.Context, s string) (string, error)

URLDecode decodes a percent-encoded URL query component.

func URLEncode

func URLEncode(_ context.Context, s string) (string, error)

URLEncode percent-encodes s for a URL query component.

func URLParse

func URLParse(_ context.Context, rawURL string) (types.URL, error)

URLParse parses rawURL into its components.

Types

This section is empty.

Jump to

Keyboard shortcuts

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