This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
generated from mrz1836/go-template
-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
model_options.go
84 lines (74 loc) · 1.81 KB
/
model_options.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package bux
import "encoding/json"
// ModelOps allow functional options to be supplied
// that overwrite default model options
type ModelOps func(m *Model)
// New set this model to a new record
func New() ModelOps {
return func(m *Model) {
m.New()
}
}
// WithClient will set the Client on the model
func WithClient(client ClientInterface) ModelOps {
return func(m *Model) {
if client != nil {
m.client = client
}
}
}
// WithXPub will set the xPub key on the model
func WithXPub(rawXpubKey string) ModelOps {
return func(m *Model) {
if len(rawXpubKey) > 0 {
m.rawXpubKey = rawXpubKey
}
}
}
// WithEncryptionKey will set the encryption key on the model (if needed)
func WithEncryptionKey(encryptionKey string) ModelOps {
return func(m *Model) {
if len(encryptionKey) > 0 {
m.encryptionKey = encryptionKey
}
}
}
// WithMetadata will add the metadata record to the model
func WithMetadata(key string, value interface{}) ModelOps {
return func(m *Model) {
if m.Metadata == nil {
m.Metadata = make(Metadata)
}
m.Metadata[key] = value
}
}
// WithMetadatas will add multiple metadata records to the model
func WithMetadatas(metadata map[string]interface{}) ModelOps {
return func(m *Model) {
if len(metadata) > 0 {
if m.Metadata == nil {
m.Metadata = make(Metadata)
}
for key, value := range metadata {
m.Metadata[key] = value
}
}
}
}
// WithMetadataFromJSON will add the metadata record to the model
func WithMetadataFromJSON(jsonData []byte) ModelOps {
return func(m *Model) {
if len(jsonData) > 0 {
if m.Metadata == nil {
m.Metadata = make(Metadata)
}
_ = json.Unmarshal(jsonData, &m.Metadata)
}
}
}
// WithPageSize will set the pageSize to use on the model in queries
func WithPageSize(pageSize int) ModelOps {
return func(m *Model) {
m.pageSize = pageSize
}
}