forked from derailed/popeye
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.go
51 lines (43 loc) · 1.21 KB
/
context.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package internal
import (
"context"
"github.com/derailed/popeye/internal/client"
)
// RunInfo describes a sanitizer run.
type RunInfo struct {
Section string
SectionGVR client.GVR
FQN string
Group string
GroupGVR client.GVR
}
// WithGroup adds a group to the context.
func WithGroup(ctx context.Context, gvr client.GVR, grp string) context.Context {
r := MustExtractRunInfo(ctx)
r.Group, r.GroupGVR = grp, gvr
return context.WithValue(ctx, KeyRunInfo, r)
}
// WithFQN adds a fqn to the context.
func WithFQN(ctx context.Context, fqn string) context.Context {
r := MustExtractRunInfo(ctx)
r.FQN = fqn
return context.WithValue(ctx, KeyRunInfo, r)
}
// MustExtractFQN extract fqn from context or die.
func MustExtractFQN(ctx context.Context) string {
r := MustExtractRunInfo(ctx)
return r.FQN
}
// MustExtractSectionGVR extract section gvr from context or die.
func MustExtractSectionGVR(ctx context.Context) string {
r := MustExtractRunInfo(ctx)
return r.SectionGVR.String()
}
// MustExtractRunInfo extracts runinfo from context or die.
func MustExtractRunInfo(ctx context.Context) RunInfo {
r, ok := ctx.Value(KeyRunInfo).(RunInfo)
if !ok {
panic("Doh! No RunInfo in context")
}
return r
}