Files
moxa/_test/context2.go
2018-12-01 17:56:55 +01:00

23 lines
332 B
Go

package main
import "context"
func get(ctx context.Context, k string) string {
var r string
var ok bool
if v := ctx.Value(k); v != nil {
r, ok = v.(string)
println(ok)
}
return r
}
func main() {
ctx := context.WithValue(context.Background(), "hello", "world")
println(get(ctx, "hello"))
}
// Output:
// true
// world