repositorypackage
0.2.0
Repository: https://github.com/dbut2/reverse-proxy.git
Documentation: pkg.go.dev
# README
Reverse Proxy
The reverse proxy package provides a wrapper around httputil.ReverseProxy
, adding the ability to create flexible, rule based routing
Usage
Import reverse-proxy
go get github.com/dbut2/reverse-proxy
In your Go code, add
import "github.com/dbut2/reverse-proxy"
Creating a reverse proxy with selectors
proxy := rp.New(
rp.Select("https://myapi.com", rp.PathIsAt("/api")),
rp.Select("https://example.com", rp.Always()),
)
Using selector options
proxy := rp.New(
rp.Select("https://private-cloud-run-instance.com", rp.IPMatches("12.34.56.78"), rp.WithOIDC()),
rp.Select("https://example.com", rp.Always()),
)
Listen and serve
proxy := rp.New(
rp.Select("https://myapi.com", rp.PathIsAt("/api")),
rp.Select("https://example.com", rp.Always()),
)
http.ListenAndServe(":8080", proxy)
Example
package main
import (
"net/http"
"github.com/dbut2/reverse-proxy"
)
func main() {
proxy := rp.New(
rp.Select("https://myapi.com", rp.PathIsAt("/api")),
rp.Select("https://example.com", rp.Always()),
)
http.ListenAndServe(":8080", proxy)
}