Documentation
¶
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Exact ¶
Exact creates new exact location matcher block
Example ¶
Match a single path exactly. Exact("/healthz") matches "/healthz" only — not "/healthz/" or "/healthz/live".
package main
import (
"github.com/moonrhythm/parapet"
"github.com/moonrhythm/parapet/pkg/headers"
"github.com/moonrhythm/parapet/pkg/location"
)
func main() {
health := location.Exact("/healthz")
health.Use(headers.SetResponse("Cache-Control", "no-store"))
s := parapet.New()
s.Use(health)
}
Output:
func Prefix ¶
Prefix creates new prefix location matcher block.
Matching only succeeds on a path-segment boundary: pattern "/admin" matches "/admin" and "/admin/anything" but not "/adminxyz".
Example ¶
Route a path prefix to its own middleware chain. Each location.* constructor returns a *block.Block: register middleware on it with Use, and that chain runs only when the request path matches — otherwise the request falls through to the rest of the server. Prefix matches on a path-segment boundary, so "/api" matches "/api" and "/api/v1" but not "/apixyz".
package main
import (
"github.com/moonrhythm/parapet"
"github.com/moonrhythm/parapet/pkg/location"
"github.com/moonrhythm/parapet/pkg/upstream"
)
func main() {
api := location.Prefix("/api")
api.Use(upstream.SingleHost("10.0.0.1:8080", &upstream.HTTPTransport{}))
s := parapet.New()
s.Use(api)
// requests outside /api continue past the block to whatever follows.
}
Output:
func RegExp ¶
RegExp creates new RegExp location matcher block
Example ¶
Match with a regular expression for cases the prefix/exact matchers cannot express — here, send requests for static assets to a dedicated upstream. The pattern is compiled once with regexp.MustCompile.
package main
import (
"github.com/moonrhythm/parapet"
"github.com/moonrhythm/parapet/pkg/location"
"github.com/moonrhythm/parapet/pkg/upstream"
)
func main() {
assets := location.RegExp(`\.(?:js|css|png|jpg|svg|woff2?)$`)
assets.Use(upstream.SingleHost("10.0.0.2:8080", &upstream.HTTPTransport{}))
s := parapet.New()
s.Use(assets)
}
Output:
Types ¶
This section is empty.