Skip to content
/ gls Public
forked from modern-go/gls

goroutine local storage (use context instead if possible)

License

Notifications You must be signed in to change notification settings

Ast-x64/gls

 
 

Repository files navigation

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)

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 70.0%
  • Assembly 19.3%
  • C++ 6.6%
  • Shell 4.1%