From 18e3a666c38024a5c6403ec031c3d09eee3be5df Mon Sep 17 00:00:00 2001 From: Tao Wen Date: Thu, 1 Mar 2018 17:56:31 +0800 Subject: [PATCH] add README --- README.md | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 09a2bcb..1412d5c 100644 --- a/README.md +++ b/README.md @@ -10,4 +10,36 @@ Thanks https://github.com/huandu/go-tls for original idea * get current goroutine id -* goroutine local storage \ No newline at end of file +* goroutine local storage + +require go version >= 1.4 + +# gls.GoID + +get the identifier unique for this goroutine + +```go +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. + +```go +gls.Set("user_id", "abc") +doSomeThing() + +func doSomeThing() { + gls.Get("user_id") // will be "abc" +} +``` \ No newline at end of file