-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathinit_opts.go
More file actions
49 lines (42 loc) · 1.07 KB
/
init_opts.go
File metadata and controls
49 lines (42 loc) · 1.07 KB
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
package arksdk
import (
"fmt"
)
type InitOption func(options *initOptions) error
// ApplyInitOptions applies the given InitOption functions to a new default
// initOptions struct and returns the first error encountered, if any.
// Exposed for use in external (arksdk_test) test packages.
func ApplyInitOptions(opts ...InitOption) error {
_, err := applyInitOptions(opts...)
return err
}
func WithExplorerURL(explorerUrl string) InitOption {
return func(o *initOptions) error {
if o.explorerUrl != "" {
return fmt.Errorf("explorer url already set")
}
if explorerUrl == "" {
return fmt.Errorf("explorer url cannot be empty")
}
o.explorerUrl = explorerUrl
return nil
}
}
func applyInitOptions(opts ...InitOption) (*initOptions, error) {
o := newDefaultInitOptions()
for _, opt := range opts {
if opt == nil {
return nil, fmt.Errorf("init option cannot be nil")
}
if err := opt(o); err != nil {
return nil, err
}
}
return o, nil
}
type initOptions struct {
explorerUrl string
}
func newDefaultInitOptions() *initOptions {
return &initOptions{}
}