bahamut: Index | Files

package gateway

import ""


Package Files

buffers.go errors.go gateway.go listener.go options.go rewriters.go utils.go

type ErrorWriter Uses

type ErrorWriter func(w http.ResponseWriter, r *http.Request, eerr elemental.Error)

ErrorWriter is a function that can be used to return a standard formatted error to the client.

type Gateway Uses

type Gateway interface {
    Start(ctx context.Context)

A Gateway can be used as an api gateway.

func New Uses

func New(listenAddr string, upstreamer Upstreamer, options ...Option) (Gateway, error)

New returns a new Gateway.

type InterceptorAction Uses

type InterceptorAction int

A InterceptorAction represents the decision on how to continue handling the request

const (
    // InterceptorActionForward means the Gateway will continue forwarding the request.
    // In that case the Interceptor must only modify the request, and MUST NOT use
    // the HTTP response writer.
    InterceptorActionForward InterceptorAction = iota + 1

    // InterceptorActionForwardWS means the Gateway will continue forwarding the request as a websocket.
    // In that case the Interceptor must only modify the request, and MUST NOT use
    // the HTTP response writer.

    // InterceptorActionForwardDirect means the Gateway will continue forwarding the request directly.
    // In that case the Interceptor must only modify the request, and MUST NOT use
    // the HTTP response writer.

    // InterceptorActionStop means the interceptor handled the request
    // and the gateway will not do anything more.

type InterceptorFunc Uses

type InterceptorFunc func(w http.ResponseWriter, req *http.Request, ew ErrorWriter) (action InterceptorAction, upstream string, err error)

An InterceptorFunc is a function that can be used to intercept and request based on its prefix and apply custom operation and returns an InterceptorAction to tell the gateway it should proceed from there. If it returns an error, the error is returned to the client as an internal server error.

NOTE: It is not possible to rewrite the request. To do so, you can use a RequestRewriter.

type Option Uses

type Option func(*gwconfig)

A Option represents possible options for the Gateway.

func OptionAllowedCORSOrigin Uses

func OptionAllowedCORSOrigin(origin string) Option

OptionAllowedCORSOrigin sets allowed CORS origin. If set to empty, or "*", the gateway will mirror whatever is set in the upcoming request Origin header. This is not secure to be used in production when a browser is calling the gateway.

By default, it is set to "*"

func OptionBlockOpenTracingHeaders Uses

func OptionBlockOpenTracingHeaders(block bool) Option

OptionBlockOpenTracingHeaders configures if the gateway should strip any open tracing related header coming from the clients.

func OptionEnableMaintenance Uses

func OptionEnableMaintenance(enabled bool) Option

OptionEnableMaintenance enables the maintenance mode.

func OptionEnableProxyProtocol Uses

func OptionEnableProxyProtocol(enabled bool, subnet string) Option

OptionEnableProxyProtocol enables and configure the support for ProxyProtocol.

func OptionEnableTrace Uses

func OptionEnableTrace(enabled bool) Option

OptionEnableTrace enables deep oxy logging.

func OptionExposePrivateAPIs Uses

func OptionExposePrivateAPIs(enabled bool) Option

OptionExposePrivateAPIs configures if the gateway should expose the private apis.

func OptionHTTPTimeouts Uses

func OptionHTTPTimeouts(read, write, idle time.Duration, disableKeepAlive bool) Option

OptionHTTPTimeouts configures the HTTP timeouts.

func OptionMetricsManager Uses

func OptionMetricsManager(metricsManager bahamut.MetricsManager) Option

OptionMetricsManager registers a given PrefixInterceptorFunc for the given path prefix.

func OptionRateLimiting Uses

func OptionRateLimiting(enabled bool, cps int, burst int) Option

OptionRateLimiting enables and configures the HTTP rate limiter.

func OptionRegisterExactInterceptor Uses

func OptionRegisterExactInterceptor(path string, f InterceptorFunc) Option

OptionRegisterExactInterceptor registers a given InterceptorFunc for the given path.

func OptionRegisterPrefixInterceptor Uses

func OptionRegisterPrefixInterceptor(prefix string, f InterceptorFunc) Option

OptionRegisterPrefixInterceptor registers a given InterceptorFunc for the given path prefix.

func OptionRegisterSuffixInterceptor Uses

func OptionRegisterSuffixInterceptor(prefix string, f InterceptorFunc) Option

OptionRegisterSuffixInterceptor registers a given InterceptorFunc for the given path suffix.

func OptionServerTLSConfig Uses

func OptionServerTLSConfig(tlsConfig *tls.Config) Option

OptionServerTLSConfig sets the tls.Config to use for the front end server.

func OptionSetCustomRequestRewriter Uses

func OptionSetCustomRequestRewriter(r RequestRewriter) Option

OptionSetCustomRequestRewriter sets a custom RequestRewriter.

func OptionSetCustomResponseRewriter Uses

func OptionSetCustomResponseRewriter(r ResponseRewriter) Option

OptionSetCustomResponseRewriter sets a custom ResponseRewriter.

func OptionTCPRateLimiting Uses

func OptionTCPRateLimiting(enabled bool, cps float64, burst int, maxConnections int) Option

OptionTCPRateLimiting enables and configures the TCP rate limiter.

func OptionUpstreamConfig Uses

func OptionUpstreamConfig(
    upstreamMaxConnsPerHost int,
    upstreamMaxIdleConns int,
    upstreamMaxIdleConnsPerHost int,
    upstreamTLSHandshakeTimeout time.Duration,
    upstreamIdleConnTimeout time.Duration,
    upstreamCircuitBreakerCond string,
    useHTTP2 bool,
) Option

OptionUpstreamConfig configures the connections to the upstream backends.

func OptionUpstreamTLSConfig Uses

func OptionUpstreamTLSConfig(tlsConfig *tls.Config) Option

OptionUpstreamTLSConfig sets the tls.Config to use for the upstream servers.

type RequestRewriter Uses

type RequestRewriter func(req *http.Request, private bool) error

A RequestRewriter can be used to rewrite the request before it is sent to the upstream. The private parameter tells if the gateway is configured or not to serve the private APIs.

type ResponseRewriter Uses

type ResponseRewriter func(*http.Response) error

A ResponseRewriter can be used to rewrite the response before it is sent back to the client

type Upstreamer Uses

type Upstreamer interface {
    Upstream(req *http.Request) (upstream string, load float64)

An Upstreamer is the interface that can conpute upstreams.

Package gateway imports 27 packages (graph). Updated 2020-04-03. Refresh now. Tools for package owners.