stripprefix

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: MIT Imports: 1 Imported by: 3

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type StripPrefix

type StripPrefix struct {
	Prefix string
}

StripPrefix middleware

Example

Pair with location.Prefix to mount a backend under a path that the backend itself does not know about: only /api/* is routed into the block, and the "/api" prefix is stripped before proxying so the upstream sees "/users".

package main

import (
	"github.com/moonrhythm/parapet"
	"github.com/moonrhythm/parapet/pkg/location"
	"github.com/moonrhythm/parapet/pkg/stripprefix"
	"github.com/moonrhythm/parapet/pkg/upstream"
)

func main() {
	api := location.Prefix("/api")
	api.Use(stripprefix.New("/api"))
	api.Use(upstream.SingleHost("10.0.0.1:8080", &upstream.HTTPTransport{}))

	s := parapet.New()
	s.Use(api)
}

func New

func New(prefix string) *StripPrefix

New creates new strip prefix middleware

Example

Remove a leading path prefix before the request reaches the rest of the chain, so "/api/users" arrives at the next handler as "/users". Requests whose path does not start with the prefix are passed through unchanged.

package main

import (
	"github.com/moonrhythm/parapet"
	"github.com/moonrhythm/parapet/pkg/stripprefix"
	"github.com/moonrhythm/parapet/pkg/upstream"
)

func main() {
	s := parapet.New()
	s.Use(stripprefix.New("/api"))
	s.Use(upstream.SingleHost("10.0.0.1:8080", &upstream.HTTPTransport{}))
}

func (StripPrefix) ServeHandler

func (m StripPrefix) ServeHandler(h http.Handler) http.Handler

ServeHandler implements middleware interface

Jump to

Keyboard shortcuts

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