Skip to content

Instantly share code, notes, and snippets.

@RicardoLinck
Created July 9, 2020 20:28
Show Gist options
  • Save RicardoLinck/34f5b7a33fc057f8b8b28644a98ba41d to your computer and use it in GitHub Desktop.
Save RicardoLinck/34f5b7a33fc057f8b8b28644a98ba41d to your computer and use it in GitHub Desktop.
package main
import (
"context"
"fmt"
)
func main() {
ctx := context.Background()
ctx = addValue(ctx)
readValue(ctx)
}
func addValue(ctx context.Context) context.Context {
return context.WithValue(ctx, "key", "test-value")
}
func readValue(ctx context.Context) {
val := ctx.Value("key")
fmt.Println(val)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment