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)
}
Output:
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{}))
}
Output:
func (StripPrefix) ServeHandler ¶
func (m StripPrefix) ServeHandler(h http.Handler) http.Handler
ServeHandler implements middleware interface
Click to show internal directories.
Click to hide internal directories.