gitee.com/quant1x/gox@v1.7.6/gls/README.md (about) 1 # goroutine local storage 2 3 [](https://sourcegraph.com/github.com/modern-go/gls?badge) 4 [](http://godoc.org/github.com/modern-go/gls) 5 [](https://travis-ci.org/modern-go/gls) 6 [](https://codecov.io/gh/modern-go/gls) 7 [](https://goreportcard.com/report/github.com/modern-go/gls) 8 [](https://raw.githubusercontent.com/modern-go/gls/master/LICENSE) 9 10 Thanks https://github.com/huandu/go-tls for original idea 11 12 * get current goroutine id 13 * goroutine local storage 14 15 require go version >= 1.4 16 17 # gls.GoID 18 19 get the identifier unique for this goroutine 20 21 ```go 22 go func() { 23 gls.GoID() 24 }() 25 go func() { 26 gls.GoID() 27 }() 28 ``` 29 30 # gls.Set / gls.Get 31 32 goroutine local storage is a `map[interface{}]interface{}` local to current goroutine 33 34 It is intended to be used by framworks to simplify context passing. 35 36 Use `context.Context` to pass context if possible. 37 38 ```go 39 gls.Set("user_id", "abc") 40 doSomeThing() 41 42 func doSomeThing() { 43 gls.Get("user_id") // will be "abc" 44 } 45 ```