Documentation
¶
Index ¶
- func WithMiddlewares(middlewares ...func(handler http.Handler) http.Handler) func(server *http.Server)
- type Opt
- func WithAcmePolicy(decision string) Opt
- func WithAutoRedirectHttps(redirect bool) Opt
- func WithCertCacheDir(certCache string) Opt
- func WithGrpcInit(opts ...func(srv *grpc.Server)) Opt
- func WithGrpcsInit(opts ...func(srv *grpc.Server)) Opt
- func WithHttpInit(opts ...func(srv *http.Server)) Opt
- func WithHttpsInit(opts ...func(srv *http.Server)) Opt
- func WithInsecurePort(insecurePort int) Opt
- func WithLogger(logger *logger.Logger) Opt
- func WithRoute(triggerExpression string) Opt
- func WithSecurePort(securePort int) Opt
- type Proxy
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Opt ¶
Opt is a function that configures a Proxy instance
func WithAcmePolicy ¶ added in v0.0.16
WithAcmePolicy sets an decision expression that specifies which host names the Acme client may respond to expression ref: github.com/graphikdb/trigger ex this.host.contains('graphikdb.io') expression attributes: (this.host<string>)
func WithAutoRedirectHttps ¶ added in v0.0.8
WithAutoRedirectHttps makes the proxy redirect http requests to https(443)
func WithCertCacheDir ¶ added in v0.0.5
WithCertCacheDir sets the directory in which certificates will be cached (default: /tmp/certs)
func WithGrpcInit ¶ added in v0.0.11
WithGrpcInit executes the functions against the insecure grpc server before it starts
func WithGrpcsInit ¶ added in v0.0.11
WithGrpcsInit executes the functions against the grpc secure server before it starts
func WithHttpInit ¶ added in v0.0.11
WithHttpInit executes the functions against the http server before it starts
func WithHttpsInit ¶ added in v0.0.11
WithHttpsInit executes the functions against the https server before it starts
func WithInsecurePort ¶
WithInsecurePort sets the port that non-encrypted traffic will be served on(default: 80)
func WithLogger ¶
WithLogger sets the proxies logger instance(optional)
func WithRoute ¶ added in v0.0.17
WithRoute adds a trigger/expression based route to the reverse proxy expression attributes: (this.http<bool>, this.grpc<bool>, this.host<string>, this.headers<map>, this.path<string>)
func WithSecurePort ¶
WithSecurePort sets the port that encrypted traffic will be served on(default: 443)
type Proxy ¶
type Proxy struct {
// contains filtered or unexported fields
}
Proxy is a secure(lets encrypt) gRPC & http reverse proxy
func New ¶
New creates a new proxy instance. A host policy & either http routes, gRPC routes, or both are required.
Example ¶
package main
import (
"context"
"fmt"
"github.com/graphikDB/gproxy"
"net/http"
"net/http/httptest"
"time"
)
func main() {
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("hello world"))
}))
defer srv.Close()
proxy, err := gproxy.New(ctx,
// serve unencrypted http/gRPC traffic on port 8080
gproxy.WithInsecurePort(8080),
// serve encrypted http/gRPC traffic on port 443
gproxy.WithSecurePort(443),
// if the request is http & the request host contains localhost, proxy to the target server
gproxy.WithRoute(fmt.Sprintf(`this.http && this.host.contains('localhost') => '%s'`, srv.URL)),
// when deploying, set the letsencrypt allowed domains
gproxy.WithAcmePolicy("this.host.contains('graphikdb.io')"))
if err != nil {
fmt.Println(err.Error())
return
}
if err := proxy.Serve(ctx); err != nil {
fmt.Println(err.Error())
return
}
}
func (*Proxy) OverrideRoutes ¶ added in v1.0.1
OverrideRoutes overrides the routes on the Proxy. It is concurrency safe
