Debian Codegraph @

execution/context.go

raw symbols SCIP
1 package execution
2
3 import (
4 "context"
5 "fmt"
6 )
7
8 type ctxKey string
9
10 const (
11 executorIDCtxKey ctxKey = "executorID"
12 executorPathCtxKey ctxKey = "executorPath"
13 executorDepthCtxKey ctxKey = "executorDepth"
14 )
15
16 func WithExecutorID(ctx context.Context, executorID string) context.Context {
17 currentPath := ExecutorPath(ctx)
18 newPath := fmt.Sprintf("%s/%s", currentPath, executorID)
19 currentDepth := ExecutorDepth(ctx)
20 newDepth := currentDepth + 1
21 ctx = context.WithValue(ctx, executorIDCtxKey, executorID)
22 ctx = context.WithValue(ctx, executorPathCtxKey, newPath)
23 ctx = context.WithValue(ctx, executorDepthCtxKey, newDepth)
24 return ctx
25 }
26
27 func ExecutorID(ctx context.Context) string {
28 v, ok := ctx.Value(executorIDCtxKey).(string)
29 if !ok {
30 return ""
31 }
32 return v
33 }
34
35 func ExecutorPath(ctx context.Context) string {
36 v, ok := ctx.Value(executorPathCtxKey).(string)
37 if !ok {
38 return ""
39 }
40 return v
41 }
42
43 func ExecutorDepth(ctx context.Context) int {
44 v, ok := ctx.Value(executorDepthCtxKey).(int)
45 if !ok {
46 return 0
47 }
48 return v
49 }