mirror of
https://github.com/SourceFellows/gobuch.git
synced 2024-10-22 22:05:35 +00:00
29 lines
432 B
Go
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)
|
||
|
|
||
|
}
|