{"id":44323607,"url":"https://github.com/vearne/gin-timeout","last_synced_at":"2026-02-11T07:10:51.713Z","repository":{"id":41265446,"uuid":"271463096","full_name":"vearne/gin-timeout","owner":"vearne","description":"Timeout Middleware for Gin framework","archived":false,"fork":false,"pushed_at":"2025-09-29T07:41:43.000Z","size":5229,"stargazers_count":110,"open_issues_count":1,"forks_count":30,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-09-29T08:17:26.671Z","etag":null,"topics":["gin","middleware","timeout"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vearne.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2020-06-11T05:52:17.000Z","updated_at":"2025-09-29T07:39:17.000Z","dependencies_parsed_at":"2024-04-24T02:45:52.386Z","dependency_job_id":"6a8aa101-691b-42ba-b8bd-4a8eff0b73df","html_url":"https://github.com/vearne/gin-timeout","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"purl":"pkg:github/vearne/gin-timeout","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vearne%2Fgin-timeout","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vearne%2Fgin-timeout/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vearne%2Fgin-timeout/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vearne%2Fgin-timeout/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vearne","download_url":"https://codeload.github.com/vearne/gin-timeout/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vearne%2Fgin-timeout/sbom","scorecard":{"id":917674,"data":{"date":"2025-08-11","repo":{"name":"github.com/vearne/gin-timeout","commit":"a2f7dc16a29393e804a31759ea1a16fdffe74794"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3.5,"checks":[{"name":"Code-Review","score":5,"reason":"Found 7/13 approved changesets -- score normalized to 5","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Dangerous-Workflow","score":10,"reason":"no dangerous workflow patterns detected","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Pinned-Dependencies","score":0,"reason":"dependency not pinned by hash detected -- score normalized to 0","details":["Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/golang-ci.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/vearne/gin-timeout/golang-ci.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/golang-ci.yml:24: update your workflow using https://app.stepsecurity.io/secureworkflow/vearne/gin-timeout/golang-ci.yml/master?enable=pin","Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/golang-ci.yml:38: update your workflow using https://app.stepsecurity.io/secureworkflow/vearne/gin-timeout/golang-ci.yml/master?enable=pin","Info:   0 out of   3 GitHub-owned GitHubAction dependencies pinned"],"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Maintained","score":2,"reason":"2 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 2","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"Token-Permissions","score":0,"reason":"detected GitHub workflow tokens with excessive permissions","details":["Warn: no topLevel permission defined: .github/workflows/golang-ci.yml:1","Info: no jobLevel write permissions found"],"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE:0","Info: FSF or OSI recognized license: MIT License: LICENSE:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":-1,"reason":"internal error: error during branchesHandler.setup: internal error: githubv4.Query: Resource not accessible by integration","details":null,"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 29 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}},{"name":"Vulnerabilities","score":0,"reason":"11 existing vulnerabilities detected","details":["Warn: Project is vulnerable to: GO-2023-2402 / GHSA-45x7-px36-x8w8","Warn: Project is vulnerable to: GO-2024-3321 / GHSA-v778-237x-gjrc","Warn: Project is vulnerable to: GO-2025-3487 / GHSA-hcg3-q754-cr77","Warn: Project is vulnerable to: GO-2023-1988 / GHSA-2wrh-6pvc-2jm9","Warn: Project is vulnerable to: GO-2023-2102 / GHSA-4374-p667-p6c8","Warn: Project is vulnerable to: GHSA-qppj-fm5r-hxr3","Warn: Project is vulnerable to: GO-2024-2687 / GHSA-4v7x-pqxf-cx7m","Warn: Project is vulnerable to: GO-2024-3333","Warn: Project is vulnerable to: GO-2025-3503 / GHSA-qxp5-gwg8-xv66","Warn: Project is vulnerable to: GO-2025-3595 / GHSA-vvgc-356p-c3xw","Warn: Project is vulnerable to: GO-2024-2611 / GHSA-8r3f-844c-mc37"],"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}}]},"last_synced_at":"2025-08-24T21:39:19.135Z","repository_id":41265446,"created_at":"2025-08-24T21:39:19.135Z","updated_at":"2025-08-24T21:39:19.135Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29329492,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-11T06:13:03.264Z","status":"ssl_error","status_checked_at":"2026-02-11T06:12:55.843Z","response_time":97,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gin","middleware","timeout"],"created_at":"2026-02-11T07:10:50.916Z","updated_at":"2026-02-11T07:10:51.705Z","avatar_url":"https://github.com/vearne.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# gin-timeout\n[![golang-ci](https://github.com/vearne/gin-timeout/actions/workflows/golang-ci.yml/badge.svg)](https://github.com/vearne/gin-timeout/actions/workflows/golang-ci.yml)\n\nTimeout Middleware for Gin framework\n\n\n* [中文 README](https://github.com/vearne/gin-timeout/blob/master/README_zh.md)\n\n### Thanks\nInspired by golang source code [http.TimeoutHandler](https://github.com/golang/go/blob/5f3dabbb79fb3dc8eea9a5050557e9241793dce3/src/net/http/server.go#L3255)\n\n### Usage\nDownload and install using go module:\n```\nexport GO111MODULE=on\ngo get github.com/vearne/gin-timeout\n```\n\n### Notice:\n- If the handler supports to be canceled, you need to pass gin.Context.Request.Context() as parameter.\n\n- If you want to get the status code of the response in middleware, you should put the middleware before the timeout middleware.\n```go\npackage main\n\nimport (\n\t\"net/http\"\n\t\"net/http/httptest\"\n\t\"time\"\n\n\t\"github.com/gin-gonic/gin\"\n\ttimeout \"github.com/vearne/gin-timeout\"\n)\n\nfunc main() {\n\treq, _ := http.NewRequest(\"GET\", \"/test\", nil)\n\n\tengine := gin.New()\n\tengine.Use(func(c *gin.Context) {\n\t\tc.Next()\n\t\tprintln(\"middleware code: \", c.Writer.Status())\n\t})\n\n\tengine.Use(timeout.Timeout(timeout.WithTimeout(10 * time.Second)))\n\t\n\tengine.GET(\"/test\", func(c *gin.Context) {\n\t\tc.Status(http.StatusBadRequest)\n\t})\n\trr := httptest.NewRecorder()\n\tengine.ServeHTTP(rr, req)\n\n\tprintln(\"response code: \", rr.Code)\n}\n```\n\n### Example\n[more example](https://github.com/vearne/gin-timeout/tree/master/example)\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"github.com/gin-gonic/gin\"\n\t\"github.com/vearne/gin-timeout\"\n\t\"io/ioutil\"\n\t\"log\"\n\t\"net/http\"\n\t\"time\"\n)\n\nfunc main() {\n\t// create new gin without any middleware\n\tengine := gin.Default()\n\n\tdefaultMsg := `{\"code\": -1, \"msg\":\"http: Handler timeout\"}`\n\t// add timeout middleware with 2 second duration\n\tengine.Use(timeout.Timeout(\n\t\ttimeout.WithTimeout(2*time.Second),\n\t\ttimeout.WithErrorHttpCode(http.StatusRequestTimeout), // optional\n\t\ttimeout.WithDefaultMsg(defaultMsg),                   // optional\n\t\ttimeout.WithCallBack(func(r *http.Request) {\n\t\t\tfmt.Println(\"timeout happen, url:\", r.URL.String())\n\t\t}),\n\t\ttimeout.WithGinCtxCallBack(func(c *gin.Context) {\n\t\t\tfmt.Println(\"timeout happen, url:\", c.Request.URL.String())\n\t\t}))) // optional\n\n\t// create a handler that will last 1 seconds\n\tengine.GET(\"/short\", short)\n\n\t// create a handler that will last 5 seconds\n\tengine.GET(\"/long\", long)\n\n\t// create a handler that will last 5 seconds but can be canceled.\n\tengine.GET(\"/long2\", long2)\n\n\t// create a handler that will last 20 seconds but can be canceled.\n\tengine.GET(\"/long3\", long3)\n\n\tengine.GET(\"/boundary\", boundary)\n\n\t// run the server\n\tlog.Fatal(engine.Run(\":8080\"))\n}\n\nfunc short(c *gin.Context) {\n\ttime.Sleep(1 * time.Second)\n\tc.JSON(http.StatusOK, gin.H{\"hello\": \"short\"})\n}\n\nfunc long(c *gin.Context) {\n\ttime.Sleep(3 * time.Second)\n\tc.JSON(http.StatusOK, gin.H{\"hello\": \"long\"})\n}\n\nfunc boundary(c *gin.Context) {\n\ttime.Sleep(2 * time.Second)\n\tc.JSON(http.StatusOK, gin.H{\"hello\": \"boundary\"})\n}\n\nfunc long2(c *gin.Context) {\n\tif doSomething(c.Request.Context()) {\n\t\tc.JSON(http.StatusOK, gin.H{\"hello\": \"long2\"})\n\t}\n}\n\nfunc long3(c *gin.Context) {\n\t// request a slow service\n\t// see  https://github.com/vearne/gin-timeout/blob/master/example/slow_service.go\n\turl := \"http://localhost:8882/hello\"\n\t// Notice:\n\t// Please use c.Request.Context(), the handler will be canceled where timeout event happen.\n\treq, _ := http.NewRequestWithContext(c.Request.Context(), http.MethodGet, url, nil)\n\tclient := http.Client{Timeout: 100 * time.Second}\n\tresp, err := client.Do(req)\n\tif err != nil {\n\t\t// Where timeout event happen, a error will be received.\n\t\tfmt.Println(\"error1:\", err)\n\t\treturn\n\t}\n\tdefer resp.Body.Close()\n\ts, err := ioutil.ReadAll(resp.Body)\n\tif err != nil {\n\t\tfmt.Println(\"error2:\", err)\n\t\treturn\n\t}\n\tfmt.Println(s)\n}\n\n// A cancelCtx can be canceled.\n// When canceled, it also cancels any children that implement canceler.\nfunc doSomething(ctx context.Context) bool {\n\tselect {\n\tcase \u003c-ctx.Done():\n\t\tfmt.Println(\"doSomething is canceled.\")\n\t\treturn false\n\tcase \u003c-time.After(5 * time.Second):\n\t\tfmt.Println(\"doSomething is done.\")\n\t\treturn true\n\t}\n}\n```\n\n### Thanks\n[![jetbrains](img/jetbrains.svg)](https://www.jetbrains.com/community/opensource/#support)\n\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvearne%2Fgin-timeout","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvearne%2Fgin-timeout","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvearne%2Fgin-timeout/lists"}