{"id":13694236,"url":"https://github.com/huandu/goroutine","last_synced_at":"2025-05-03T01:32:08.305Z","repository":{"id":57482841,"uuid":"46269904","full_name":"huandu/goroutine","owner":"huandu","description":"[DEPRECATED] Expose goroutine id to wild world. Alternative approach is https://github.com/huandu/go-tls","archived":true,"fork":false,"pushed_at":"2018-02-06T03:04:58.000Z","size":316,"stargazers_count":111,"open_issues_count":0,"forks_count":15,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-11-12T20:46:58.333Z","etag":null,"topics":["go","goroutine","hack","runtime"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/huandu.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-11-16T11:14:09.000Z","updated_at":"2024-07-09T09:49:16.000Z","dependencies_parsed_at":"2022-09-03T09:51:25.968Z","dependency_job_id":null,"html_url":"https://github.com/huandu/goroutine","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huandu%2Fgoroutine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huandu%2Fgoroutine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huandu%2Fgoroutine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/huandu%2Fgoroutine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/huandu","download_url":"https://codeload.github.com/huandu/goroutine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252130454,"owners_count":21699095,"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":["go","goroutine","hack","runtime"],"created_at":"2024-08-02T17:01:27.452Z","updated_at":"2025-05-03T01:32:06.994Z","avatar_url":"https://github.com/huandu.png","language":"Go","readme":"# Hacking goroutine #\n\n[![Build Status](https://travis-ci.org/huandu/goroutine.png?branch=master)](https://travis-ci.org/huandu/goroutine)\n\n**[DEPRECATED]**\n\n* If you're still looking for a solution to get goroutine id, please go to https://github.com/v2pro/plz/tree/master/gls.\n* If you're looking for a package to create TLS or local storage for a goroutine transparently, use https://github.com/huandu/go-tls.\n\nPackage goroutine is merely a hack.\nIt exports goroutine id to outside so that you can use it for whatever purpose.\nHowever, it's highly recommended to not use this package in your daily life.\nIt may be broken at any go release as it's a hack.\n\n## Usage ##\n\nGet the latest version through `go get -u github.com/huandu/goroutine`.\n\nGet current goroutine id with `goroutine.GoroutineId()`.\n\n```go\n// Get id of current goroutine.\nvar id int64 = goroutine.GoroutineId()\nprintln(id)\n```\n\nSee [godoc](https://godoc.org/github.com/huandu/goroutine) for more details.\n\n## Supported builds ##\n\nPackage goroutine is not well tested due to lack of test machines.\nIdeally, it should work on all go \u003e= go1.5.\n\nTested platforms.\n* Darwin (Mac OSX 10.11.6) + amd64 CPU\n    * go1.5.1\n    * go1.6.3\n    * go1.7\n    * go1.7.1\n    * go1.7.3\n    * go1.7.4\n    * go1.7.5\n    * go1.8\n    * go1.8.1\n    * go1.9\n    * go1.9.2\n* Travis CI (See https://travis-ci.org/huandu/goroutine)\n    * go1.5\n    * go1.5.1\n    * go1.5.2\n    * go1.5.3\n    * go1.5.4\n    * go1.6\n    * go1.6.1\n    * go1.6.2\n    * go1.6.3\n    * go1.7\n    * go1.7.1\n    * go1.7.2\n    * go1.7.3\n    * go1.7.4\n    * go1.7.5\n    * go1.8\n    * go1.8.1\n    * go1.8.2\n    * go1.8.3\n    * go1.9\n    * go1.9.1\n    * go1.9.2\n\n## How it works ##\n\nGo runtime inside a Go program binary is statically linked. It means, if I know Go version and runtime source code for\nthis version, I can copy struct declaration from runtime package source to my package and cast runtime internal pointers\nto its underlying struct safely. As Go source code is open for everyone, I can always find the right struct for an\ninteresting runtime pointer and then manipulate it.\n\nIn this package, I just get current goroutine pointer (copy the `getg()` implementation from compiler), cast it to a right\nstruct and then return the id. It sounds simple but of course not. The struct `g` refers to many other internal types defined\nin `runtime` package. I cannot simply copy some necessary types to make it work. I have to scan all types and constants in\n`runtime` and its internal packages to make the struct `g` well defined. Another challenge is that Go authors update\n`runtime` structs in nearly every major version (or even in a minor version). I have to maintain hacked code for every Go\nrelease respectively. I develop a semi-automatical tool to make things easier. The tool is not smart enough.  I may need to\nthink of other better way to avoid to generate hacked source code for every Go release.\n\nNOTE: Starting from go1.7.2, Go compiler generates some constant definitions for `runtime` package according to build flags and\nenvironment when building. It makes current hack impossible to handle all posibile flags and environment combinations. I make a\nhack to detour it and no impact to the major task of this package - get goroutine id. However, it's not a perfect solution.\n\nI'm thinking of a perfect solution. If you have any suggestion, please open issue and let me know. Many thanks.\n\n## License ##\n\nThis package is licensed under MIT license. See LICENSE for details.\n","funding_links":[],"categories":["Go"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuandu%2Fgoroutine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhuandu%2Fgoroutine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhuandu%2Fgoroutine/lists"}