mirror of
https://github.com/SourceFellows/gobuch.git
synced 2025-08-02 21:02:15 +02:00
initial import
This commit is contained in:
28
best-practices/context-value-nono/main.go
Normal file
28
best-practices/context-value-nono/main.go
Normal file
@ -0,0 +1,28 @@
|
||||
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)
|
||||
|
||||
}
|
Reference in New Issue
Block a user