lenonqing / gls

goroutine local storage (use context instead if possible)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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"
}

About

goroutine local storage (use context instead if possible)

License:Apache License 2.0


Languages

Language:Go 67.3%Language:Assembly 22.4%Language:C 6.4%Language:Shell 4.0%