Skip to content
goroutine local storage (use context instead if possible)
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
.travis.yml
LICENSE
README.md
gls.go
gls_test.go
go_tls.h
goid.go gofmt Mar 1, 2018
goid_386.s
goid_amd64.s
goid_amd64p32.s import from plz Feb 28, 2018
goid_arm.s
goid_arm64.s
goid_test.go import from plz Feb 28, 2018
test.sh

README.md

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"
}
You can’t perform that action at this time.