-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathstacked_builder.go
66 lines (50 loc) · 1.09 KB
/
stacked_builder.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
package stl
import "context"
// NewStacked creates an instance of stacked Builder.
func NewStacked() Builder {
return &stackedBuilder{}
}
type stackedBuilder struct {
prefix string
shs []string
exs []string
v Vault
}
func (t *stackedBuilder) Shared(name string) Builder {
if name == "" {
panic("resource name could not be empty")
}
t.prefix = t.prefix + name
t.shs = append(t.shs, t.prefix)
return t
}
func (t *stackedBuilder) Exclusive(name string) Builder {
if name == "" {
panic("resource name could not be empty")
}
t.prefix = t.prefix + name
t.exs = append(t.exs, t.prefix)
return t
}
func (t *stackedBuilder) ListShared() []string {
return t.shs
}
func (t *stackedBuilder) ListExclusive() []string {
return t.exs
}
func (t *stackedBuilder) ToTx() Tx {
return t
}
func (t *stackedBuilder) ToLocker(v Vault) Locker {
t.v = v
return t
}
func (t *stackedBuilder) Lock() {
_ = t.v.Lock(context.Background(), t)
}
func (t *stackedBuilder) Unlock() {
t.v.Unlock(t)
}
func (t *stackedBuilder) LockWithContext(ctx context.Context) error {
return t.v.Lock(ctx, t)
}