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 ¶
- Variables
- func CheckTemplate(path string) error
- func Concrete(raw, sample string) (string, error)
- func Conflicts(a, b string) bool
- func IsTemplate(path string) bool
- func Matches(registered, requested string) bool
- func Normalize(raw string) (string, error)
- func Resolve(registered []string, requested string) (int, error)
Constants ¶
This section is empty.
Variables ¶
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 ¶
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 ¶
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 ¶
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 ¶
IsTemplate reports whether any segment of a normalised path is a {name} or :name parameter.
func Matches ¶
Matches reports whether a normalised registered path (which may be a template) matches a normalised requested path.
func Normalize ¶
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.
Types ¶
This section is empty.