rewrite

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: Apache-2.0 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 rewrite holds the pure path logic behind KDexPage rewrite mode (kdex-tech/host-manager#217), shared by the page controller's static placeholder check and the host's request-time dispatch.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("rewrite: path values name no target route")

ErrNotFound reports request values that name no target route: a single-segment {name} value holding a '/' (a decoded %2F, which must not let one wildcard span segments of the target), or an empty value that leaves '//' (a missing segment, not a malformed one). It is a 404, not a 400.

View Source
var ErrUnsafe = errors.New("rewrite: substituted path is unsafe")

ErrUnsafe reports a dispatch path that would contain '//' or a '.'/'..' segment after substitution. The CRD's CEL constrains the author's template; this guards the request-supplied values substituted into it.

Functions

func Placeholders

func Placeholders(tmpl string) []string

Placeholders returns the bare names of the {name} / {name...} placeholders in a rewrite path template, in order.

func Target

func Target(basePath, exact, tmpl, patternPath string, value func(string) string) (string, error)

Target builds the path a rewrite dispatches to. An empty tmpl returns exact, the path the target's base route answers at (its basePath since #220), so the dispatch lands on that route rather than on a redirect that would expose the target URL. Otherwise each {name} (or {name...}) is replaced by value(name) and the result is joined to basePath with exactly one '/'. patternPath is the alias page's own pattern: it says which names are multi-segment wildcards.

It returns ErrUnsafe (400) when a value would introduce '//' or a '.'/'..' segment, and ErrNotFound (404) when a single-segment value holds a '/' or when the only '//' comes from an empty value.

func UnknownPlaceholders

func UnknownPlaceholders(tmpl, patternPath string) []string

UnknownPlaceholders returns the placeholders in tmpl that are not wildcard names in patternPath -- they could never be substituted at request time.

Types

This section is empty.

Jump to

Keyboard shortcuts

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