Skip to content

srvc/appctx

Repository files navigation

appctx

CI GoDoc GitHub release GitHub

Examples

Global

// canceled this context when received os signals for termination
ctx := appctx.Global()

inspired by github.com/moby/buildkit/util/appcontext

Clone

baseCtx, cancel := context.WithCancel(context.Background())
baseCtx = context.WithValue(baseCtx, "user_id", 123)

newCtx := appctx.Clone(baseCtx)
cancel()

fmt.Println(newCtx.Value("user_id"), baseCtx.Value("user_id")) // => 123 123
fmt.Println(newCtx.Err(), baseCtx.Err()) // => <nil> context canceled