gitee.com/quant1x/gox@v1.21.2/gls/README.md (about)

     1  # goroutine local storage
     2  
     3  [![Sourcegraph](https://sourcegraph.com/github.com/modern-go/gls/-/badge.svg)](https://sourcegraph.com/github.com/modern-go/gls?badge)
     4  [![GoDoc](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](http://godoc.org/github.com/modern-go/gls)
     5  [![Build Status](https://travis-ci.org/modern-go/gls.svg?branch=master)](https://travis-ci.org/modern-go/gls)
     6  [![codecov](https://codecov.io/gh/modern-go/gls/branch/master/graph/badge.svg)](https://codecov.io/gh/modern-go/gls)
     7  [![rcard](https://goreportcard.com/badge/github.com/modern-go/gls)](https://goreportcard.com/report/github.com/modern-go/gls)
     8  [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://raw.githubusercontent.com/modern-go/gls/master/LICENSE)
     9  
    10  Thanks https://github.com/huandu/go-tls for original idea
    11  
    12  * get current goroutine id
    13  * goroutine local storage
    14  
    15  require go version >= 1.4
    16  
    17  # gls.GoID
    18  
    19  get the identifier unique for this goroutine
    20  
    21  ```go
    22  go func() {
    23  	gls.GoID()
    24  }()
    25  go func() {
    26  	gls.GoID()
    27  }()
    28  ```
    29  
    30  # gls.Set / gls.Get
    31  
    32  goroutine local storage is a `map[interface{}]interface{}` local to current goroutine
    33  
    34  It is intended to be used by framworks to simplify context passing.
    35  
    36  Use `context.Context` to pass context if possible.
    37  
    38  ```go
    39  gls.Set("user_id", "abc")
    40  doSomeThing()
    41  
    42  func doSomeThing() {
    43  	gls.Get("user_id") // will be "abc"
    44  }
    45  ```