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