-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions.go
62 lines (54 loc) · 1.25 KB
/
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
package tokendirectory
import (
"fmt"
"log/slog"
"time"
)
type Option func(*TokenDirectory) error
func WithLogger(logger *slog.Logger) Option {
return func(td *TokenDirectory) error {
td.log = logger
return nil
}
}
func WithProviders(providers ...Provider) Option {
return func(td *TokenDirectory) error {
if len(providers) == 0 {
return fmt.Errorf("no provider specified")
}
for _, p := range providers {
if _, ok := td.providers[p.GetID()]; ok {
return fmt.Errorf("provider %q already exists", p.GetID())
}
td.providers[p.GetID()] = p
}
return nil
}
}
func WithUpdateFuncs(functions ...OnUpdateFunc) Option {
return func(td *TokenDirectory) error {
td.onUpdate = append(td.onUpdate, functions...)
return nil
}
}
func WithUpdateInterval(interval time.Duration) Option {
return func(td *TokenDirectory) error {
if interval < 1*time.Minute {
return fmt.Errorf("updateInterval must be greater then 1 minute")
}
td.updateInterval = interval
return nil
}
}
func WithChainIDs(chainIDs ...uint64) Option {
return func(td *TokenDirectory) error {
td.chainIDs = chainIDs
return nil
}
}
func WithSources(sources ...SourceType) Option {
return func(td *TokenDirectory) error {
td.sources = sources
return nil
}
}