Documentation ¶
Index ¶
- type Middleware
- type 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 WithLetsEncryptHosts(allowedHosts []string) Opt
- func WithLogger(logger *logger.Logger) Opt
- func WithMiddlewares(middlewares ...Middleware) Opt
- func WithSecurePort(securePort int) Opt
- func WithTrigger(triggerExpression string) Opt
- type Proxy
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Middleware ¶
Middleware is an http middleware
type Opt ¶
Opt is a function that configures a Proxy instance
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(optional)
func WithLetsEncryptHosts ¶ added in v0.0.7
WithLetsEncryptHosts sets the letsencryp host policy on the proxy(required)
func WithLogger ¶
WithLogger sets the proxies logger instance(optional)
func WithMiddlewares ¶
func WithMiddlewares(middlewares ...Middleware) Opt
WithMiddlewares sets the http middlewares on encrypted & non-encrypted traffic(optional)
func WithSecurePort ¶
WithSecurePort sets the port that encrypted traffic will be served on(optional)
func WithTrigger ¶ added in v0.0.7
WithTrigger adds a trigger/expression based route to the reverse proxy
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.WithTrigger(fmt.Sprintf(`this.http && this.host.contains('localhost') => '%s'`, srv.URL)), // when deploying, set the letsencrypt allowed domains gproxy.WithLetsEncryptHosts([]string{ // "www.graphikdb.io", })) if err != nil { fmt.Println(err.Error()) return } if err := proxy.Serve(ctx); err != nil { fmt.Println(err.Error()) return } }
Output:
func (*Proxy) OverrideTriggers ¶ added in v0.0.12
OverrideTriggers overrides the triggers-routes on the Proxy. It is concurrency safe