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.
Click to show internal directories.
Click to hide internal directories.