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

redirect

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: 4 Imported by: 0

Documentation

Overview

Package redirect answers matching paths with a redirect.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

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

New redirects requests whose path matches a rule, keeping the original query string. Register it with App.Use or App.UsePrefix, so it runs before routing. Registering it on a group panics, since it would only see paths that already have a route; on a single route it logs a warning the first time it runs.

Types

type Config

type Config struct {
	// Rules maps a path to its target. A path ending in "*" matches a prefix,
	// and a "*" in the target is replaced by the rest of the path, still
	// escaped. A target without a scheme or host is a path on this site.
	//
	// 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
	// StatusCode is the redirect status. Zero uses 301 Moved Permanently.
	StatusCode int
}

Config maps request paths to redirect targets.

Jump to

Keyboard shortcuts

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