This section is empty.


This section is empty.


This section is empty.


type ErrorWriter

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

type Gateway interface {
	Start(ctx context.Context)

A Gateway can be used as an api gateway.

func New

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

New returns a new Gateway.

type InterceptorAction

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

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

type Option func(*gwconfig)

A Option represents possible options for the Gateway.

func OptionAllowedCORSOrigin

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

func OptionBlockOpenTracingHeaders(block bool) Option

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

func OptionEnableMaintenance

func OptionEnableMaintenance(enabled bool) Option

OptionEnableMaintenance enables the maintenance mode.

func OptionEnableProxyProtocol

func OptionEnableProxyProtocol(enabled bool, subnet string) Option

OptionEnableProxyProtocol enables and configure the support for ProxyProtocol.

func OptionEnableTrace

func OptionEnableTrace(enabled bool) Option

OptionEnableTrace enables deep oxy logging.

func OptionExposePrivateAPIs

func OptionExposePrivateAPIs(enabled bool) Option

OptionExposePrivateAPIs configures if the gateway should expose the private apis.

func OptionHTTPTimeouts

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

OptionHTTPTimeouts configures the HTTP timeouts.

func OptionMetricsManager

func OptionMetricsManager(metricsManager bahamut.MetricsManager) Option

OptionMetricsManager registers a given PrefixInterceptorFunc for the given path prefix.

func OptionRateLimiting

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

OptionRateLimiting enables and configures the HTTP rate limiter.

func OptionRegisterExactInterceptor

func OptionRegisterExactInterceptor(path string, f InterceptorFunc) Option

OptionRegisterExactInterceptor registers a given InterceptorFunc for the given path.

func OptionRegisterPrefixInterceptor

func OptionRegisterPrefixInterceptor(prefix string, f InterceptorFunc) Option

OptionRegisterPrefixInterceptor registers a given InterceptorFunc for the given path prefix.

func OptionRegisterSuffixInterceptor

func OptionRegisterSuffixInterceptor(prefix string, f InterceptorFunc) Option

OptionRegisterSuffixInterceptor registers a given InterceptorFunc for the given path suffix.

func OptionServerTLSConfig

func OptionServerTLSConfig(tlsConfig *tls.Config) Option

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

func OptionSetCustomRequestRewriter

func OptionSetCustomRequestRewriter(r RequestRewriter) Option

OptionSetCustomRequestRewriter sets a custom RequestRewriter.

func OptionSetCustomResponseRewriter

func OptionSetCustomResponseRewriter(r ResponseRewriter) Option

OptionSetCustomResponseRewriter sets a custom ResponseRewriter.

func OptionTCPRateLimiting

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

OptionTCPRateLimiting enables and configures the TCP rate limiter.

func OptionUpstreamConfig

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

func OptionUpstreamTLSConfig(tlsConfig *tls.Config) Option

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

type RequestRewriter

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

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

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

An Upstreamer is the interface that can conpute upstreams.


Path Synopsis