location

package
v0.18.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2026 License: MIT Imports: 4 Imported by: 2

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exact

func Exact(pattern string) *block.Block

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)
}

func Prefix

func Prefix(pattern string) *block.Block

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.
}

func RegExp

func RegExp(pattern string) *block.Block

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)
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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