https://github.com/nikandfor/goid
https://github.com/nikandfor/goid
gls go golang goroutine id tls
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/nikandfor/goid
- Owner: nikandfor
- License: mit
- Created: 2020-08-19T18:52:17.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-02-09T20:33:33.000Z (over 4 years ago)
- Last Synced: 2023-07-27T22:24:35.208Z (almost 3 years ago)
- Topics: gls, go, golang, goroutine, id, tls
- Language: Go
- Homepage:
- Size: 20.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# goid
Do not use this package (https://golang.org/doc/faq#no_goroutine_id).
Or use: example [./goid_example_test.go](./goid_example_test.go), doc https://pkg.go.dev/github.com/nikandfor/goid?tab=doc
tl;dr
```go
func f() {
id := goid.ID() // <-- that's why you are here
s := goid.StartPC() // goroutine main (root) function entry point ("id := goid.ID()").
g := goid.GoPC() // go statement pc ("go f()")
}
```
# goroutine local storage
There is some rarely used field in goroutine struct. So it could be used to save some stuff.
```go
type Storage struct {
// ... any fields ...
}
func f() {
s := (*Storage)(goid.GLoad()) // nil at first
goid.GSave(unsafe.Pointer(&Storage{ /* ... */}))
// ... later event in some other function ...
s1 := (*Storage)(goid.GLoad())
// use s1.YourField
}
```
# One more time: it's fun, play with it, but try not to use in real code