forked from gopasspw/gopass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
context.go
69 lines (58 loc) · 1.64 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package action
import "context"
type contextKey int
const (
ctxKeyClip contextKey = iota
ctxKeyForce
ctxKeyPasswordOnly
ctxKeyPrintQR
)
// WithClip returns a context with the value for clip (for copy to clipboard)
// set
func WithClip(ctx context.Context, clip bool) context.Context {
return context.WithValue(ctx, ctxKeyClip, clip)
}
// IsClip returns the value of clip or the default (false)
func IsClip(ctx context.Context) bool {
bv, ok := ctx.Value(ctxKeyClip).(bool)
if !ok {
return false
}
return bv
}
// WithForce returns a context with the value for force set
func WithForce(ctx context.Context, force bool) context.Context {
return context.WithValue(ctx, ctxKeyForce, force)
}
// IsForce returns the value of force or the default (false)
func IsForce(ctx context.Context) bool {
bv, ok := ctx.Value(ctxKeyForce).(bool)
if !ok {
return false
}
return bv
}
// WithPasswordOnly returns a context with the value of password only set
func WithPasswordOnly(ctx context.Context, pw bool) context.Context {
return context.WithValue(ctx, ctxKeyPasswordOnly, pw)
}
// IsPasswordOnly returns the value of password only or the default (false)
func IsPasswordOnly(ctx context.Context) bool {
bv, ok := ctx.Value(ctxKeyPasswordOnly).(bool)
if !ok {
return false
}
return bv
}
// WithPrintQR returns a context with the value of print QR set
func WithPrintQR(ctx context.Context, qr bool) context.Context {
return context.WithValue(ctx, ctxKeyPrintQR, qr)
}
// IsPrintQR returns the value of print QR or the default (false)
func IsPrintQR(ctx context.Context) bool {
bv, ok := ctx.Value(ctxKeyPrintQR).(bool)
if !ok {
return false
}
return bv
}