endpointpath

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: MIT Imports: 4 Imported by: 0 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 endpointpath is the rule that maps a URL a merchant served to the product registered at that path. Only the path is compared: host, scheme, port and query are dropped, because a merchant behind a proxy sees an internal host and the query holds the buyer's input. A registered segment written {name} or :name matches any one segment.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalid   = errors.New("endpoint must be an http(s) URL or a path starting with /")
	ErrNoMatch   = errors.New("no registered endpoint matches")
	ErrAmbiguous = errors.New("several registered endpoints match")
	// ErrPartialTemplate's text is shown to merchants as is.
	ErrPartialTemplate = errors.New("a template parameter must be a whole path segment, like /files/{id}; a brace inside a segment, like file-{id}.json, is not supported")
)

Functions

func CheckTemplate

func CheckTemplate(path string) error

CheckTemplate refuses a normalised registered path with a brace outside a whole {name} segment. Matching treats such a segment literally, so no request could ever resolve to it.

func Concrete

func Concrete(raw, sample string) (string, error)

Concrete returns the full http(s) URL raw with every template parameter segment replaced by sample, so a templated endpoint can be probed. Everything else is kept byte-for-byte.

func Conflicts

func Conflicts(a, b string) bool

Conflicts reports whether two normalised registered paths cannot both belong to one merchant: they are equal, or both are templates that some request would match. A fixed path beside a template is allowed, because the fixed one wins.

func IsTemplate

func IsTemplate(path string) bool

IsTemplate reports whether any segment of a normalised path is a {name} or :name parameter.

func Matches

func Matches(registered, requested string) bool

Matches reports whether a normalised registered path (which may be a template) matches a normalised requested path.

func Normalize

func Normalize(raw string) (string, error)

Normalize returns the path of a full http(s) URL or of a path starting with "/", without query, fragment or trailing slash ("/" for the root). Each segment is decoded on its own after the split, so an encoded slash cannot create a segment the merchant's router never saw; a segment that decodes to "/", "." or ".." is refused.

func Resolve

func Resolve(registered []string, requested string) (int, error)

Resolve returns the index in registered (normalised paths) of the path that serves requested: the equal fixed path, else the only matching template.

Types

This section is empty.

Jump to

Keyboard shortcuts

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