Documentation
¶
Overview ¶
Package redirects manages URL redirects.
contract.go holds the frozen wave-0 contract (types and interfaces only). The implementation arrives in wave 1.
Index ¶
- Constants
- Variables
- func HostOf(raw string) string
- func Middleware(svc Service) func(http.Handler) http.Handler
- func NormalizePath(p string) string
- func Reserved(path string) bool
- func ValidStatus(code int) bool
- type DeleteResponse
- type ImportResult
- type ListQuery
- type Module
- type Redirect
- type RowError
- type SaveRequest
- type SavedEvent
- type Service
- type ValidationError
Constants ¶
const HookSaved = "redirects.saved"
HookSaved is emitted (async) after redirects change; payload SavedEvent.
const Perm = "redirects.manage"
Perm is the permission for managing redirects.
Variables ¶
var ErrNotFound = errors.New("redirects: not found")
ErrNotFound is returned for unknown redirects.
var ReservedPrefixes = []string{"/admin", "/api", "/mcp", "/auth", "/webhooks", "/media", "/static", "/checkout",
"/account", "/healthz", "/readyz"}
ReservedPrefixes are application paths a redirect may never take over: saving one is a validation error and the middleware never answers them.
Functions ¶
func Middleware ¶
Middleware answers GET/HEAD requests whose path has an enabled redirect (exact, case-sensitive, trailing-slash-insensitive) and counts the hit. The original query string is kept unless the target has its own.
func NormalizePath ¶
NormalizePath returns p as stored and matched: percent-decoded, query and fragment removed, a leading "/" and no trailing "/" (except the root). Matching stays case-sensitive.
func Reserved ¶
Reserved reports whether path is one of ReservedPrefixes or below one, by whole path segment and ignoring case ("/admin" and "/Admin/x" are, "/administration" and "/my-account" are not).
func ValidStatus ¶
ValidStatus reports whether code is an allowed redirect status.
Types ¶
type DeleteResponse ¶
DeleteResponse is returned by DELETE /v1/redirects/{id}.
type ImportResult ¶
ImportResult summarizes a CSV import.
type ListQuery ¶
type ListQuery struct {
Search string `json:"search"`
Page int `json:"page"`
PerPage int `json:"per_page"`
Sort string `json:"sort"`
Order string `json:"order"`
}
ListQuery filters Service.List.
type Module ¶
type Module struct{}
Module is the redirects kernel.Module.
type SaveRequest ¶
type SaveRequest struct {
ID string `json:"id"`
FromPath string `json:"from_path"`
ToURL string `json:"to_url"`
Status int `json:"status" doc:"301 (default), 302, 307 or 308"`
Enabled *bool `json:"enabled,omitempty" doc:"default true"`
}
SaveRequest is the body of POST /v1/redirects (create when ID is empty).
type SavedEvent ¶
type SavedEvent struct {
Action string `json:"action"` // save | delete | import
ID string `json:"id,omitempty"`
FromPath string `json:"from_path,omitempty"`
Count int `json:"count,omitempty"`
}
SavedEvent is the HookSaved payload.
type ValidationError ¶
ValidationError lists invalid fields (values are i18n keys).
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string