urlkey

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2026 License: Apache-2.0 Imports: 4 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package urlkey derives stable cache-key strings from URLs by applying pragmatic HTTP URL normalization.

The normalization follows RFC 3986 equivalence guidance and HTTP URI rules where applicable (RFC 3986 §6.2, RFC 7230 §2.7.3). It is intended for cache key generation, not as a full URI canonicalization framework.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Normalize

func Normalize(u *url.URL) string

Normalize returns a normalized URL string suitable for use as a cache key.

It normalizes scheme/host case, default ports, dot-segments, and percent-encoding (for path and query), and excludes fragments.

For opaque URLs (u.Opaque != ""), the opaque value is returned unchanged.

Example
package main

import (
	"fmt"
	"net/url"

	"github.com/bartventer/httpcache/pkg/urlkey"
)

func main() {
	u, err := url.Parse(
		"https://example.com:8443/abc?query=param&another=value#fragment=part1&part2",
	)
	if err != nil {
		panic(err)
	}
	key := urlkey.Normalize(u)
	fmt.Println(key)
}
Output:
https://example.com:8443/abc?query=param&another=value

Types

This section is empty.

Jump to

Keyboard shortcuts

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