gateway

package
v0.6.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 30, 2019 License: BSD-3-Clause Imports: 27 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Gateway

type Gateway struct {
	Name             string        // The name of the Gateway for registration
	Addr             string        // TCP address to listen on, ":http" if empty
	HandleInterrupt  bool          // Should SIGINT and SIGTERM interrupts be handled?
	DisableKeepAlive bool          // Should TCP keep alive be disabled?
	GracePeriod      time.Duration // Timeout for graceful shutdown of open connections
	TLSConfig        *tls.Config   // optional TLS config, used by ServeTLS

	// ReadTimeout is the maximum duration for reading the entire
	// request, including the body.
	//
	// Because ReadTimeout does not let Handlers make per-request
	// decisions on each request body's acceptable deadline or
	// upload rate, most users will prefer to use
	// ReadHeaderTimeout. It is valid to use them both.
	ReadTimeout time.Duration

	// ReadHeaderTimeout is the amount of time allowed to read
	// request headers. The connection's read deadline is reset
	// after reading the headers and the Handler can decide what
	// is considered too slow for the body.
	ReadHeaderTimeout time.Duration

	// WriteTimeout is the maximum duration before timing out
	// writes of the response. It is reset whenever a new
	// request's header is read. Like ReadTimeout, it does not
	// let Handlers make decisions on a per-request basis.
	WriteTimeout time.Duration

	// IdleTimeout is the maximum amount of time to wait for the
	// next request when keep-alives are enabled. If IdleTimeout
	// is zero, the value of ReadTimeout is used. If both are
	// zero, ReadHeaderTimeout is used.
	IdleTimeout time.Duration

	// MaxHeaderBytes controls the maximum number of bytes the
	// server will read parsing the request header's keys and
	// values, including the request line. It does not limit the
	// size of the request body.
	// If zero, DefaultMaxHeaderBytes is used.
	MaxHeaderBytes int

	// TLSNextProto optionally specifies a function to take over
	// ownership of the provided TLS connection when an NPN/ALPN
	// protocol upgrade has occurred. The map key is the protocol
	// name negotiated. The Handler argument should be used to
	// handle HTTP requests and will initialize the Request's TLS
	// and RemoteAddr if not already set. The connection is
	// automatically closed when the function returns.
	// If TLSNextProto is not nil, HTTP/2 support is not enabled
	// automatically.
	TLSNextProto map[string]func(*http.Server, *tls.Conn, http.Handler)

	// RequestIDHeaderName optionally customizes the name of the
	// response header for the request id.
	// If empty "X-Request-Id" will be used.
	RequestIDHeaderName string

	// RequestIDGenerator optionally customizes how request ids
	// are generated.
	// If nil then `httpx.Request.GenerateID` will be used.
	RequestIDGenerator httpx.StringExtractor

	// Handlers define handlers to run on all request before
	// any other dispatch or validation.
	// Example uses would be rate limiting or authentication.
	Handlers []httpx.Handler

	// HandlersTimeout is the maximum amount of time to wait for
	// all gateway-level handlers to complete.
	// If the timeout is exceeded the entire request is aborted.
	HandlersTimeout time.Duration

	// InternalServerErrorHandler optionally customizes the
	// response returned to the user agent when the gateway
	// encounters an error trying to service the requst before
	// the corresponding endpoint has been determined.
	// If nil the default handler will return a 500 status code
	// with an empty body.
	InternalServerErrorHandler httpx.ErrorHandler

	// NotFoundHandler optionally customizes the response
	// returned to the user agent when no endpoint is configured
	// service a request path.
	// If nil the default handler will return a 404 status code
	// with an empty body.
	NotFoundHandler httpx.Handler

	// Registrar implements sd.Registrar and registers
	// the gateway service with a service registry, using the
	// Gateway's `Name` field. If nil, no registration occurs.
	Registrar sd.Registrar

	// RegistrationURLHook provides the *url.URL to be used in
	// the Registrar's `Register` method. If `Registrar` is nil,
	// this hook is not called. If this hook is nil, no service is
	// registered via `Register`.
	RegistrationURLHook URLHook

	// CheckURLHook provides the *url.URL to be used in
	// the Registrar's `AddCheck` method. If `Registrar` is nil,
	// this hook is not called. If this hook is nil, no check is
	// registered via `AddCheck`.
	CheckURLHook URLHook

	// ErrorHook optionally customizes how errors encountered
	// servicing a request are disposed.
	// If nil the request id and error are sent to the standard
	// library `log.Println` function.
	ErrorHook httpx.ErrorHook

	// CompletionHook optionally customizes the behavior after
	// a request has been serviced.
	// If nil no action will be taken.
	CompletionHook httpx.CompletionHook
	// contains filtered or unexported fields
}

func (*Gateway) Address

func (g *Gateway) Address() string

func (*Gateway) Serve

func (g *Gateway) Serve(services ...*service.Service) merry.Error

func (*Gateway) ServeHTTP

func (g *Gateway) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Gateway) ServeTLS

func (g *Gateway) ServeTLS(services ...*service.Service) merry.Error

func (*Gateway) Shutdown

func (g *Gateway) Shutdown() (err error)

func (*Gateway) String added in v0.3.0

func (g *Gateway) String() string

String implements `expvar.Var.String`

type URLHook added in v0.3.1

type URLHook func() (*url.URL, merry.Error)

func (URLHook) InvokeSafely added in v0.3.1

func (h URLHook) InvokeSafely() (u *url.URL, err merry.Error, exception merry.Error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL