Documentation ¶
Index ¶
- Constants
- type Gateway
- func (g *Gateway) Serve(services []service.Service, auxiliaries ...auxiliary.Server) error
- func (g *Gateway) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (g *Gateway) ServeTLS(services []service.Service, auxiliaries ...auxiliary.Server) error
- func (g *Gateway) Shutdown() (err error)
- func (g *Gateway) String() string
Constants ¶
View Source
const ( // RequestIdGenerationMetricKey is the `ResponseSnapshot` metric for generating the request id RequestIdGenerationMetricKey = "request-id-generation" // ParseQueryParametersMetricKey is the `ResponseSnapshot` metric for parsing the request query parameters ParseQueryParametersMetricKey = "parse-query" // RunGatewayHandlersMetricKey is the `ResponseSnapshot` metric for running the Gateway level handlers RunGatewayHandlersMetricKey = "handlers" // FindEndpointMetricKey is the `ResponseSnapshot` metric for resolving the request's endpoint FindEndpointMetricKey = "find-endpoint" // ValidateQueryParametersMetricKey is the `ResponseSnapshot` metric for validating the request query parameters ValidateQueryParametersMetricKey = "validate-query" // RunEndpointPipelineMetricKey is the `ResponseSnapshot` metric for running the endpoint's pipeline RunEndpointPipelineMetricKey = "pipeline" // SerializeResponseMetricKey is the `ResponseSnapshot` metric for serializing the response SerializeResponseMetricKey = "serialization" )
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 Address 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 `json:"-"` // 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) `json:"-"` // 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 `json:"-"` // 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 `json:"-"` // HandlersTimeout is the maximum amout 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 `json:"-"` // 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 `json:"-"` // 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 // 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 func() (*url.URL, error) // ErrorHook optionally customizes how errors encountered // servicing a request are disposed. // If nil the error is sent to the `Error` level of the // `Logger` field with the request id as a field. ErrorHook httpx.ErrorHook `json:"-"` // CompletionHook optionally customizes the behavior after // a request has been serviced. // If nil no action will be taken. CompletionHook httpx.CompletionHook `json:"-"` // Logger optionally specifies the logger to use by the // Gateway. // If nil all logging is disabled. Logger *zap.Logger `json:"-"` // contains filtered or unexported fields }
Click to show internal directories.
Click to hide internal directories.