context
package main
import (
"context"
"fmt"
)
func f(ctx context.Context) {
context.WithValue(ctx, "foo", -6)
}
func main() {
ctx := context.TODO()
f(ctx)
fmt.Println(ctx.Value("foo"))
}
- A. -6
- B. 0
- C.
<nil>
- D: panic
Answer
Try it
C
context1
package main
import(
"fmt"
"encoding/json"
"context"
)
func main() {
data, _ := json.Marshal(context.WithValue(context.Background(), "a", "b"))
fmt.Println(string(data))
}
Answer
Try it
{"Context":{}}