{"modulePath":"github.com/fox-toolkit/timeout","version":"v1.1.1","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package timeout\n\n## Constants\n\n```go\nconst None = time.Duration(0)\n```\n\n## Functions\n\n```go\nfunc DefaultResponse(c *fox.Context)\n```\nDefaultResponse sends a default 503 Service Unavailable response.\n\n```go\nfunc Middleware(dt time.Duration, opts ...Option) fox.MiddlewareFunc\n```\nMiddleware returns a [fox.MiddlewareFunc](/github.com/fox-toolkit/fox#MiddlewareFunc) that runs handlers with the given time limit.\n\nThe middleware calls the next handler to handle each request, but if a call runs for longer than its time limit, the handler responds with a 503 Service Unavailable error (see [DefaultResponse](#DefaultResponse)). After such a timeout, writes by the handler to its ResponseWriter will return [http.ErrHandlerTimeout](/net/http#ErrHandlerTimeout).\n\nThe timeout middleware supports the [http.Pusher](/net/http#Pusher) interface but does not support the [http.Hijacker](/net/http#Hijacker) or [http.Flusher](/net/http#Flusher) interfaces.\n\nIndividual routes can override the timeout duration using the [OverrideHandler](#OverrideHandler) option. It's also possible to set the read and write deadline for individual route using the [OverrideRead](#OverrideRead) and [OverrideWrite](#OverrideWrite) option. If dt \\\u003c= 0 (or None), this is a passthrough middleware but per-route options remain effective.\n\n```go\nfunc OverrideHandler(dt time.Duration) fox.RouteOption\n```\nOverrideHandler returns a RouteOption that sets a custom timeout duration for a specific route. This allows individual routes to have different timeout values than the global timeout. Passing a value \\\u003c= 0 (or None) disables the timeout for this route.\n\n```go\nfunc OverrideRead(dt time.Duration) fox.RouteOption\n```\nOverrideRead returns a RouteOption that sets the read deadline for the underlying connection. This controls how long the server will wait before timing out while reading the request body. Passing a value \\\u003c= 0 (or None) clears the read deadline for this route.\n\n```go\nfunc OverrideWrite(dt time.Duration) fox.RouteOption\n```\nOverrideWrite returns a RouteOption that sets the write deadline for the underlying connection. This controls how long the server will wait before timing out writes to the client. Passing a value \\\u003c= 0 (or None) clears the write deadline for this route.\n\n## Types\n\n```go\ntype Option interface {\n\t// contains filtered or unexported methods\n}\n```\n\n```go\nfunc WithResponse(h fox.HandlerFunc) Option\n```\nWithResponse sets a custom response handler function for the middleware. This function will be invoked when a timeout occurs, allowing for custom responses to be sent back to the client. If not set, the middleware use [DefaultResponse](#DefaultResponse).\n\n","path":"github.com/fox-toolkit/timeout","name":"timeout","synopsis":"","isRedistributable":true}
