Help us shape the future of Go! Take the 2026 Go Developer Survey

rewrite

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package rewrite routes matching paths as other paths.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(configs ...Config) zinc.Middleware

New changes the routed path of matching requests without a redirect. Query parameters remain untouched. Register it with App.Use or App.UsePrefix, so it runs before routing. Registering it on a group panics, since the route can no longer change there; on a single route it logs a warning the first time it runs.

Types

type Config

type Config struct {
	// Rules maps a path to the path to route instead. A path ending in "*"
	// matches a prefix, and a "*" in the target is replaced by the rest of
	// the path.
	//
	// When several rules match, an exact rule wins over every "*" rule, and
	// among "*" rules the longest prefix wins: with "/*" and "/api/*", a
	// request for /api/pets always takes "/api/*". The order is fixed when
	// New runs, so every request agrees.
	Rules map[string]string
}

Config maps incoming paths to internal paths.

Jump to

Keyboard shortcuts

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