{"id":13414123,"url":"https://github.com/vrecan/death","last_synced_at":"2025-03-14T20:31:12.757Z","repository":{"id":28364427,"uuid":"31878325","full_name":"vrecan/death","owner":"vrecan","description":"Managing go application shutdown with signals.","archived":false,"fork":false,"pushed_at":"2022-05-28T20:23:00.000Z","size":1203,"stargazers_count":196,"open_issues_count":0,"forks_count":20,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-09-30T21:49:17.397Z","etag":null,"topics":["death","go","shutdown","signals"],"latest_commit_sha":null,"homepage":"https://vreco.fly.dev/blog/post/Concurrent%20Graceful%20Shutdown%20in%20Go","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/vrecan.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}},"created_at":"2015-03-09T03:50:40.000Z","updated_at":"2024-08-08T10:05:37.000Z","dependencies_parsed_at":"2022-08-19T03:50:32.041Z","dependency_job_id":null,"html_url":"https://github.com/vrecan/death","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vrecan%2Fdeath","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vrecan%2Fdeath/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vrecan%2Fdeath/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vrecan%2Fdeath/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vrecan","download_url":"https://codeload.github.com/vrecan/death/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221504092,"owners_count":16833954,"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":["death","go","shutdown","signals"],"created_at":"2024-07-30T20:01:58.304Z","updated_at":"2025-03-14T20:31:12.751Z","avatar_url":"https://github.com/vrecan.png","language":"Go","readme":"# Death [![Build Status](https://travis-ci.org/vrecan/death.svg?branch=master)](https://travis-ci.org/vrecan/death) [![Coverage Status](https://coveralls.io/repos/github/vrecan/death/badge.svg?branch=master)](https://coveralls.io/github/vrecan/death?branch=master) [![Go Reference](https://pkg.go.dev/badge/github.com/vrecan/death/v3.svg)](https://pkg.go.dev/github.com/vrecan/death/v3) [![Join the chat at https://gitter.im/vrecan/death](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/vrecan/death?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\n\u003cp\u003eSimple library to make it easier to manage the death of your application.\u003c/p\u003e\n\n## Get The Library\n\nUse gopkg.in to import death based on your logger.\n\n| Version | Go Get URL                                                                           | source                                                           | doc                                                  | Notes                                                                                                                                                                                                                                                                                                |\n| ------- | ------------------------------------------------------------------------------------ | ---------------------------------------------------------------- | ---------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| 3.x     | [github.com/vrecan/death/v3](https://github.com/vrecan/death/tree/release-branch.v3) | [source](https://github.com/vrecan/death/tree/release-branch.v3) | [doc](https://pkg.go.dev/github.com/vrecan/death/v3) | This removes the need for an independent logger. By default death will not log but will return an error if all the closers do not properly close. If you want to provide a logger just satisfy the deathlog.Logger interface. This also uses go modules so import it as `github.com/vrecan/death/v3` |\n| 2.x     | [gopkg.in/vrecan/death.v2](https://gopkg.in/vrecan/death.v2)                         | [source](https://github.com/vrecan/death/tree/v2.0)              | [doc](https://godoc.org/gopkg.in/vrecan/death.v2)    | This supports loggers who _do not_ return an error from their `Error` and `Warn` functions like [logrus](https://github.com/sirupsen/logrus)                                                                                                                                                         |\n| 1.x     | [gopkg.in/vrecan/death.v1](https://gopkg.in/vrecan/death.v1)                         | [souce](https://github.com/vrecan/death/tree/v1.0)               | [doc](https://godoc.org/gopkg.in/vrecan/death.v1)    | This supports loggers who _do_ return an error from their `Error` and `Warn` functions like [seelog](https://github.com/cihub/seelog)                                                                                                                                                                |\n\nExample\n\n```bash\ngo get github.com/vrecan/death/v3\n```\n\n## Use The Library\n\n```go\npackage main\n\nimport (\n\tDEATH \"github.com/vrecan/death/v3\"\n\tSYS \"syscall\"\n)\n\nfunc main() {\n\tdeath := DEATH.NewDeath(SYS.SIGINT, SYS.SIGTERM) //pass the signals you want to end your application\n\t//when you want to block for shutdown signals\n\tdeath.WaitForDeath() // this will finish when a signal of your type is sent to your application\n}\n```\n\n### Close Other Objects On Shutdown\n\n\u003cp\u003eOne simple feature of death is that it can also close other objects when shutdown starts\u003c/p\u003e\n\n```go\npackage main\n\nimport (\n\t\"log\"\n\tDEATH \"github.com/vrecan/death/v3\"\n\tSYS \"syscall\"\n\t\"io\"\n)\n\nfunc main() {\n\tdeath := DEATH.NewDeath(SYS.SIGINT, SYS.SIGTERM) //pass the signals you want to end your application\n\tobjects := make([]io.Closer, 0)\n\n\tobjects = append(objects, \u0026NewType{}) // this will work as long as the type implements a Close method\n\n\t//when you want to block for shutdown signals\n\terr := death.WaitForDeath(objects...) // this will finish when a signal of your type is sent to your application\n\tif err != nil {\n\t\tlog.Println(err)\n\t\tos.Exit(1)\n\t}\n}\n\ntype NewType struct {\n}\n\nfunc (c *NewType) Close() error {\n\treturn nil\n}\n\n```\n\n### Or close using an anonymous function\n\n```go\npackage main\n\nimport (\n\tDEATH \"github.com/vrecan/death/v3\"\n\tSYS \"syscall\"\n)\n\nfunc main() {\n\tdeath := DEATH.NewDeath(SYS.SIGINT, SYS.SIGTERM) //pass the signals you want to end your application\n\t//when you want to block for shutdown signals\n\tdeath.WaitForDeathWithFunc(func(){\n\t\t//do whatever you want on death\n\t})\n}\n```\n\n# Release Process\n\n## Rules for release branches:\n\n- If you are releasing a new major version you need to branch off of master into a branch `release-branch.v#` (example `release-branch.v2` for a 2.x release)\n- If you are releasing a minor or patch update to an existing major release make sure to merge master into the release branch\n\n## Rules for tagging and publishing the release\n\nWhen you are ready to publish the release make sure you...\n\n1. Merge your changes into the correct release branch.\n2. Check out the release branch locally (example: `git pull origin release-branch.v3`)\n3. Create a new tag for the specific release version you will publish (example: `git tag v3.0.1`)\n4. Push the tag up to github (example: `git push origin v3.0.1`)\n5. Go to the release tab in github\n6. Select the target branch as the release branch and type in the tag name (tagname should include `v` so example: `v3.0.1`)\n7. Write a title and a well worded description on exactly what is in this change\n8. Click publish release\n","funding_links":[],"categories":["Utilities","Programming","工具库`可以提升效率的通用代码库和工具`","公用事业公司","实用工具","實用工具","工具库","Utility","Go"],"sub_categories":["Utility/Miscellaneous","Golang","HTTP Clients","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","查询语","Advanced Console UIs","实用程序/Miscellaneous","Fail injection","高級控制台界面","交流","高级控制台界面"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvrecan%2Fdeath","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvrecan%2Fdeath","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvrecan%2Fdeath/lists"}