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

shared

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

Documentation

Overview

Package shared holds helpers used by more than one Zinc middleware package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Config

func Config[T any](name string, configs []T) T

Config returns the configuration passed to a middleware's New, or the zero value when there is none, so every field falls back to its default.

func EscapedTail added in v0.7.2

func EscapedTail(u *url.URL, n int) string

EscapedTail returns the escaped form of the last n bytes of u.Path, so a redirect built from it keeps encoded characters such as %2F encoded.

func ExpandTarget added in v0.7.2

func ExpandTarget(to, tail string) string

ExpandTarget replaces the first "*" in to with tail, or appends tail when to has none.

func ExternalTarget added in v0.7.2

func ExternalTarget(to string) bool

ExternalTarget reports whether a rule's target names a scheme or host, so it is meant to leave the site. Decide this on the configured target, before any part of the request path is put into it.

func PathWithRawQuery

func PathWithRawQuery(path, rawQuery string) string

PathWithRawQuery appends rawQuery to path.

func ResponseStatus

func ResponseStatus(rw zinc.ResponseWriter, err error) int

ResponseStatus is the status a request ended with: the one written, or the one the error handler sends for err.

func SameSitePath added in v0.7.2

func SameSitePath(path string) string

SameSitePath makes an escaped request path safe to send as a redirect target: the result starts with exactly one slash, so a browser resolves it on this site, and backslashes, spaces and control characters are escaped. A path starting "//" or "/\" would otherwise name another host.

Types

type RoutingWarning added in v0.5.2

type RoutingWarning struct {
	// contains filtered or unexported fields
}

RoutingWarning warns once when middleware that changes which route a request takes, such as redirect or rewrite, runs after a route was already chosen. On a group Zinc refuses it at registration, so this catches the remaining case, a single route: it works for that path only, and a rewrite can no longer change the route.

func NewRoutingWarning added in v0.5.2

func NewRoutingWarning(name string) *RoutingWarning

NewRoutingWarning returns a RoutingWarning for the middleware called name.

func (*RoutingWarning) Check added in v0.5.2

func (w *RoutingWarning) Check(c *zinc.Context)

Check logs the warning the first time c has a matched route.

type Rules added in v0.7.3

type Rules struct {
	// contains filtered or unexported fields
}

Rules is a compiled set of path rules, as used by rewrite, redirect and proxy. A pattern ending in "*" matches any path starting with the text before the "*"; any other pattern matches one path exactly.

When several rules match a path, the winner is fixed when the rules are compiled, not by map order: an exact rule beats every "*" rule, and among "*" rules the one with the longest literal prefix wins. Two different prefixes that both match a path can't have the same length, so there are no ties to break.

func CompileRules added in v0.7.3

func CompileRules(rules map[string]string) *Rules

CompileRules copies rules into precedence order, dropping empty patterns.

func (*Rules) Len added in v0.7.3

func (r *Rules) Len() int

Len reports how many rules were compiled.

func (*Rules) Match added in v0.7.3

func (r *Rules) Match(path string) (to, tail string, prefix, ok bool)

Match finds the winning rule for path. It returns the rule's target, the part of path after a prefix pattern, and whether a prefix pattern matched rather than an exact one.

func (*Rules) Rewrite added in v0.7.3

func (r *Rules) Rewrite(path string) (string, bool)

Rewrite applies the winning rule to path. A "*" in the target is replaced by the part of path after the matched prefix, or that part is appended when the target has no "*".

Jump to

Keyboard shortcuts

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