https://github.com/tigerwill90/foxtimeout
Timeout middleware for Fox
https://github.com/tigerwill90/foxtimeout
fox go golang middleware timeout
Last synced: 6 months ago
JSON representation
Timeout middleware for Fox
- Host: GitHub
- URL: https://github.com/tigerwill90/foxtimeout
- Owner: tigerwill90
- License: mit
- Created: 2023-08-16T17:34:45.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2026-01-06T20:56:28.000Z (7 months ago)
- Last Synced: 2026-01-12T01:33:37.667Z (6 months ago)
- Topics: fox, go, golang, middleware, timeout
- Language: Go
- Homepage:
- Size: 40 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
[](https://pkg.go.dev/github.com/tigerwill90/foxtimeout)
[](https://github.com/tigerwill90/foxtimeout/actions?query=workflow%3Atests)
[](https://goreportcard.com/report/github.com/tigerwill90/foxtimeout)
[](https://codecov.io/gh/tigerwill90/foxtimeout)


# Foxtimeout
Foxtimeout is a middleware for [Fox](https://github.com/tigerwill90/fox) which ensure that a handler do not exceed the
configured timeout limit.
## Disclaimer
Foxtimeout's API is closely tied to the Fox router, and it will only reach v1 when the router is stabilized.
During the pre-v1 phase, breaking changes may occur and will be documented in the release notes.
## Getting started
### Installation
````shell
go get -u github.com/tigerwill90/foxtimeout
````
### Feature
- Allows for custom timeout response to better suit specific use cases.
- Tightly integrates with the Fox ecosystem for enhanced performance and scalability.
- Supports dynamic timeout configuration on a per-route & per-request basis using custom `Resolver`.
### Usage
````go
package main
import (
"errors"
"fmt"
"log"
"net/http"
"time"
"github.com/tigerwill90/fox"
"github.com/tigerwill90/foxtimeout"
)
func main() {
f := fox.MustRouter(
fox.DefaultOptions(),
fox.WithMiddleware(
foxtimeout.Middleware(2*time.Second),
),
)
f.MustAdd(fox.MethodGet, "/hello/{name}", func(c *fox.Context) {
_ = c.String(http.StatusOK, fmt.Sprintf("Hello %s\n", c.Param("name")))
})
// Disable timeout the middleware for this route
f.MustAdd(fox.MethodGet, "/download/{filepath}", DownloadHandler, foxtimeout.HandlerTimeout(foxtimeout.NoTimeout))
// Use 15s timeout instead of the global 2s for this route
f.MustAdd(fox.MethodGet, "/workflow/{id}/start", WorkflowHandler, foxtimeout.HandlerTimeout(15*time.Second))
if err := http.ListenAndServe(":8080", f); err != nil && !errors.Is(err, http.ErrServerClosed) {
log.Fatalln(err)
}
}
````