rulematch

package
v3.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package rulematch provides pattern compilation and capture substitution shared by redirect and rewrite rules. Callers choose the pattern syntax and own destination normalization.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CaptureTokens

func CaptureTokens(pattern *regexp.Regexp, input string, unescaped bool) *strings.Replacer

CaptureTokens matches input and returns a replacer for its numbered capture groups ($1, $2, ...), or nil when the pattern does not match. A match without capture groups returns a non-nil replacer that leaves the target unchanged. Captures are preserved verbatim unless unescaped is set. In that case, path segments are escaped before substitution because rewrite decodes the resulting path again. This prevents a literal "%2e%2e" capture from becoming "..". Empty values and trailing slashes are preserved in either mode.

Adapted from https://github.com/labstack/echo/blob/master/middleware/rewrite.go.

func DotSegments added in v3.7.0

func DotSegments(s string) int

DotSegments counts the "." and ".." segments of s as some reader may: "%2e" is a dot, "\", "%2f" and "%5c" are slashes, and "?" and "#" end a segment, not the count, so a capture cannot hide one.

func MustCompilePath added in v3.7.0

func MustCompilePath(from string) *regexp.Regexp

MustCompilePath compiles a rewrite pattern: path text matched as written, each "*" a "(.*)" capture.

func MustCompileRegexp added in v3.7.0

func MustCompileRegexp(from string) *regexp.Regexp

MustCompileRegexp compiles a redirect pattern: regexp syntax with its groups and flags, each "*" a "(.*)" capture. An invalid pattern panics.

Types

This section is empty.

Jump to

Keyboard shortcuts

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