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: 0

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