{"id":28581738,"url":"https://github.com/teivah/onecontext","last_synced_at":"2025-06-11T04:32:55.584Z","repository":{"id":57500127,"uuid":"200272656","full_name":"teivah/onecontext","owner":"teivah","description":"Set of Go context's utilities.","archived":false,"fork":false,"pushed_at":"2021-05-06T20:22:49.000Z","size":227,"stargazers_count":54,"open_issues_count":0,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-05T16:37:15.322Z","etag":null,"topics":["concurrency","context","go","golang","happy","merge"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/teivah.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":"2019-08-02T17:21:38.000Z","updated_at":"2025-02-03T17:33:12.000Z","dependencies_parsed_at":"2022-08-28T20:01:24.841Z","dependency_job_id":null,"html_url":"https://github.com/teivah/onecontext","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teivah%2Fonecontext","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teivah%2Fonecontext/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teivah%2Fonecontext/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teivah%2Fonecontext/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/teivah","download_url":"https://codeload.github.com/teivah/onecontext/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teivah%2Fonecontext/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259200164,"owners_count":22820575,"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":["concurrency","context","go","golang","happy","merge"],"created_at":"2025-06-11T04:31:30.075Z","updated_at":"2025-06-11T04:32:55.554Z","avatar_url":"https://github.com/teivah.png","language":"Go","readme":"# teivah/onecontext\n\n[![Go Report Card](https://goreportcard.com/badge/github.com/teivah/onecontext)](https://goreportcard.com/report/github.com/teivah/onecontext)\n\n`teivah/onecontext` is a set of context utilities.\n\n## One Context\n\nHave you ever faced the situation where you have to merge multiple existing contexts?\nIf not, then you might, eventually.\n\nFor example, we can face the situation where we are building an application using a library that gives us a global context (for example, `urfave/cli`).\nThis context expires once the application is stopped.\n\nMeanwhile, we are exposing a gRPC service like this:\n\n```go\nfunc (f *Foo) Get(ctx context.Context, bar *Bar) (*Baz, error) {\n\t\n}\n```\n\nHere, we receive another context provided by gRPC.\n\nThen, in the `Get` implementation, we want to query a database and provide a context for that.\n\nIdeally, we would like to provide a merged context that would expire either:\n- When the application is stopped\n- Or when the received gRPC context expires\n\nIt's is precisely the purpose of this library.\n\nIn our case, we can now merge the two contexts in a single one like this:\n\n```go\nctx, cancel := onecontext.Merge(ctx1, ctx2)\n```\n\nIt returns a merged context that we can now propagate.\n\n## Detach\n\n`onecontext.Detach` returns a context detached from the original cancellation signal. It can be helpful, for example, if we implement an HTTP handler and that we have to pass a context to another goroutine that may expire after we send back a response.\n\n## Reset Values\n\n`onecontext.ResetValues` reset the values of an existing context.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteivah%2Fonecontext","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fteivah%2Fonecontext","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteivah%2Fonecontext/lists"}