Files
moxa/_test/context.go
Marc Vertes c75807dec9 Fix type assertions for runtime objects. Work in progress.
Function typeAssert() now returns the concrete value of interface{}
object defined in the runtime.

What is missing is actual type checking against provided type, and
support for the variant returning 2 values, the concrete value and
boolean status.
2018-12-01 14:49:56 +01:00

20 lines
293 B
Go

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