-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
context.go
41 lines (31 loc) 路 891 Bytes
/
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
package helper
import (
"context"
"github.com/helmwave/helmwave/pkg/release/uniqname"
)
type contextReleaseUniqKey struct{}
func ContextWithReleaseUniq(ctx context.Context, name uniqname.UniqName) context.Context {
return context.WithValue(ctx, contextReleaseUniqKey{}, name)
}
func ContextGetReleaseUniq(ctx context.Context) (uniqname.UniqName, bool) {
v := ctx.Value(contextReleaseUniqKey{})
switch v := v.(type) {
case uniqname.UniqName:
return v, true
default:
return "", false
}
}
type contextLifecycleTypeKey struct{}
func ContextWithLifecycleType(ctx context.Context, typ string) context.Context {
return context.WithValue(ctx, contextLifecycleTypeKey{}, typ)
}
func ContextGetLifecycleType(ctx context.Context) (string, bool) {
v := ctx.Value(contextLifecycleTypeKey{})
switch v := v.(type) {
case string:
return v, true
default:
return "", false
}
}