{"id":29151356,"url":"https://github.com/karpeleslab/contexter","last_synced_at":"2025-07-01T00:09:08.765Z","repository":{"id":57651378,"uuid":"449187045","full_name":"KarpelesLab/contexter","owner":"KarpelesLab","description":null,"archived":false,"fork":false,"pushed_at":"2023-06-30T05:25:30.000Z","size":12,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-06-20T05:23:35.060Z","etag":null,"topics":[],"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/KarpelesLab.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}},"created_at":"2022-01-18T07:41:02.000Z","updated_at":"2022-01-18T07:41:17.000Z","dependencies_parsed_at":"2024-06-20T04:41:08.632Z","dependency_job_id":"68c50037-ef05-4033-87e9-924b17eb6da2","html_url":"https://github.com/KarpelesLab/contexter","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/KarpelesLab/contexter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KarpelesLab%2Fcontexter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KarpelesLab%2Fcontexter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KarpelesLab%2Fcontexter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KarpelesLab%2Fcontexter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KarpelesLab","download_url":"https://codeload.github.com/KarpelesLab/contexter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KarpelesLab%2Fcontexter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262870877,"owners_count":23377314,"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":[],"created_at":"2025-07-01T00:09:04.455Z","updated_at":"2025-07-01T00:09:08.661Z","avatar_url":"https://github.com/KarpelesLab.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![GoDoc](https://godoc.org/github.com/KarpelesLab/contexter?status.svg)](https://godoc.org/github.com/KarpelesLab/contexter)\n\n# Contexter\n\nA dirty piece of code for fetching `context.Context` from the stack when it\ncannot be passed normally.\n\n## But why?\n\nI turned out to need access to context.Context from a `MarshalJSON()` method\nand found out there is no way to pass it easily. This is one of my attempts\nat passing ctx across the stack.\n\nSo if your method that accepts a `context.Context` calls `json.Marshal()`, it\nis likely the `MarshalJSON()` methods will be able to fetch the context using\n`contexter.Context()`.\n\nThis said, we now have the [pjson](https://github.com/KarpelesLab/pjson) lib\nthat accepts contextes and is able to cleanly pass the context to the encoded\nobjects.\n\n### My soul doesn't hurt enough\n\nMore stack based golang dark magic can be found online:\n\n* https://github.com/jtolio/gls\n\n## It doesn't work\n\nThere can be various reasons why this doesn't work, or stopped working.\n\n* The method receiving a `context.Context` has been inlined and its parameters aren't available\n* The variable containing the `context.Context` isn't used and was overwritten\n* You're into a different goroutine (which means a new stack)\n* Something changed in Go's runtime, stack display format, etc\n* The architecture you're using does something that's not accounted for in this module\n\nThis is not an exact science, and using this package may result in the end of\nthe world, or your program crashing in ways go can't recover. You've been\nwarned.\n\n# Usage\n\n```go\nctx := contexter.Context()\n```\n\nThis will automatically fetch the closest context.Context object found in the\nstack that was passed as a context.Context object, or nil if none were found.\n\n```go\nvar ctx context.Context\nif contexter.Find(\u0026ctx) {\n\t// use ctx\n}\n```\n\nThis alternative version can find other kind of interfaces on the stack.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkarpeleslab%2Fcontexter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkarpeleslab%2Fcontexter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkarpeleslab%2Fcontexter/lists"}