{"id":16767394,"url":"https://github.com/vardius/shutdown","last_synced_at":"2025-04-10T19:13:21.771Z","repository":{"id":57483217,"uuid":"192620196","full_name":"vardius/shutdown","owner":"vardius","description":"Simple go signals handler for performing graceful shutdown by executing callback function","archived":false,"fork":false,"pushed_at":"2020-06-22T06:43:30.000Z","size":26,"stargazers_count":20,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T16:56:05.117Z","etag":null,"topics":["graceful","graceful-shutdown","gracefully","shutdown","signal","signals"],"latest_commit_sha":null,"homepage":"","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/vardius.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["vardius"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2019-06-18T22:23:32.000Z","updated_at":"2024-06-13T04:22:15.000Z","dependencies_parsed_at":"2022-08-27T20:02:45.086Z","dependency_job_id":null,"html_url":"https://github.com/vardius/shutdown","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vardius%2Fshutdown","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vardius%2Fshutdown/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vardius%2Fshutdown/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vardius%2Fshutdown/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vardius","download_url":"https://codeload.github.com/vardius/shutdown/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248280190,"owners_count":21077412,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["graceful","graceful-shutdown","gracefully","shutdown","signal","signals"],"created_at":"2024-10-13T06:09:03.723Z","updated_at":"2025-04-10T19:13:21.748Z","avatar_url":"https://github.com/vardius.png","language":"Go","funding_links":["https://github.com/sponsors/vardius"],"categories":[],"sub_categories":[],"readme":"⏲️ shutdown\n================\n[![Build Status](https://travis-ci.org/vardius/shutdown.svg?branch=master)](https://travis-ci.org/vardius/shutdown)\n[![Go Report Card](https://goreportcard.com/badge/github.com/vardius/shutdown)](https://goreportcard.com/report/github.com/vardius/shutdown)\n[![codecov](https://codecov.io/gh/vardius/shutdown/branch/master/graph/badge.svg)](https://codecov.io/gh/vardius/shutdown)\n[![](https://godoc.org/github.com/vardius/shutdown?status.svg)](https://pkg.go.dev/github.com/vardius/shutdown)\n[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/vardius/shutdown/blob/master/LICENSE.md)\n\n\u003cimg align=\"right\" height=\"180px\" src=\"https://github.com/vardius/gorouter/blob/master/website/src/static/img/logo.png?raw=true\" alt=\"logo\" /\u003e\n\nshutdown - Simple go signals handler for performing graceful shutdown by executing callback function\n\n📖 ABOUT\n==================================================\nContributors:\n\n* [Rafał Lorenz](http://rafallorenz.com)\n\nWant to contribute ? Feel free to send pull requests!\n\nHave problems, bugs, feature ideas?\nWe are using the github [issue tracker](https://github.com/vardius/shutdown/issues) to manage them.\n\n## 📚 Documentation\n\nFor __examples__ **visit [godoc#pkg-examples](http://godoc.org/github.com/vardius/shutdown#pkg-examples)**\n\nFor **GoDoc** reference, **visit [pkg.go.dev](https://pkg.go.dev/github.com/vardius/shutdown)**\n\n🚏 HOW TO USE\n==================================================\n\nFor detailed breakdown of example [How to handle signals with Go to graceful shutdown HTTP server](https://rafallorenz.com/go/handle-signals-to-graceful-shutdown-http-server/)\n\n## 🏫 Basic example\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\t\"log\"\n\t\"net\"\n\t\"net/http\"\n\t\"os\"\n\t\"syscall\"\n\t\"time\"\n\n    \"github.com/vardius/shutdown\"\n)\n\nfunc main() {\n\tctx, cancel := context.WithCancel(context.Background())\n\tdefer cancel()\n\n\tmux := http.NewServeMux()\n\tmux.HandleFunc(\"/\", func(w http.ResponseWriter, req *http.Request) {\n\t\tfmt.Fprintf(w, \"Hello!\")\n\t})\n\n\thttpServer := \u0026http.Server{\n\t\tAddr:    \":8080\",\n\t\tHandler: mux,\n\t\tBaseContext: func(_ net.Listener) context.Context { return ctx },\n\t}\n\n\tstop := func() {\n\t\tgracefulCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second)\n\t\tdefer cancel()\n\n\t\tif err := httpServer.Shutdown(gracefulCtx); err != nil {\n\t\t\tlog.Printf(\"shutdown error: %v\\n\", err)\n\t\t} else {\n\t\t\tlog.Printf(\"gracefully stopped\\n\")\n\t\t}\n\t}\n\n\t// Run server\n\tgo func() {\n\t\tif err := httpServer.ListenAndServe(); err != http.ErrServerClosed {\n\t\t\tlog.Printf(\"HTTP server ListenAndServe: %v\", err)\n\t\t\tos.Exit(1)\n\t\t}\n\t}()\n\n\tshutdown.GracefulStop(stop) // will block until shutdown signal is received\n}\n```\n\n📜 [License](LICENSE.md)\n-------\n\nThis package is released under the MIT license. See the complete license in the package\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvardius%2Fshutdown","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvardius%2Fshutdown","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvardius%2Fshutdown/lists"}