gobuch/best-practices/context-value-nono/main.go
2020-08-21 06:26:40 +02:00

29 lines
432 B
Go

package main
import (
"context"
"fmt"
)
type contextKey int
const usernameKey contextKey = iota
func businessCall(username string) {
//.. was wichtiges
fmt.Println(username)
}
func main() {
ctx := context.Background()
vCtx := context.WithValue(ctx, usernameKey, "bob")
//.. einiges anderes
businessCall(vCtx.Value(usernameKey).(string))
//Variante2
username := "bob"
//.. einiges anderes
businessCall(username)
}