Documentation ¶
Index ¶
- type Middleware
- type Opt
- func WithAutoRedirectHttps(redirect bool) Opt
- func WithCertCacheDir(certCache string) 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 WithStreamInterceptors(sinterceptors ...grpc.StreamServerInterceptor) Opt
- func WithTrigger(triggerExpression string) Opt
- func WithUnaryInterceptors(uinterceptors ...grpc.UnaryServerInterceptor) 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 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 WithStreamInterceptors ¶
func WithStreamInterceptors(sinterceptors ...grpc.StreamServerInterceptor) Opt
WithStreamInterceptors adds gRPC stream interceptors to the proxy instance
func WithTrigger ¶ added in v0.0.7
WithTrigger adds a trigger/expression based route to the reverse proxy
func WithUnaryInterceptors ¶
func WithUnaryInterceptors(uinterceptors ...grpc.UnaryServerInterceptor) Opt
WithUnaryInterceptors adds gRPC unary interceptors to the proxy instance
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")) })) 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') => { "target": "%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: