Skip to content

Latest commit

 

History

History
45 lines (32 loc) · 1.35 KB

README.md

File metadata and controls

45 lines (32 loc) · 1.35 KB

goroutine local storage

Sourcegraph GoDoc Build Status codecov rcard License

Thanks https://github.com/huandu/go-tls for original idea

  • get current goroutine id
  • goroutine local storage

require go version >= 1.4

gls.GoID

get the identifier unique for this goroutine

go func() {
	gls.GoID()
}()
go func() {
	gls.GoID()
}()

gls.Set / gls.Get

goroutine local storage is a map[interface{}]interface{} local to current goroutine

It is intended to be used by framworks to simplify context passing.

Use context.Context to pass context if possible.

gls.Set("user_id", "abc")
doSomeThing()

func doSomeThing() {
	gls.Get("user_id") // will be "abc"
}