/
settings.go
189 lines (159 loc) · 4.88 KB
/
settings.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
package settings
import (
"fmt"
"os"
"strconv"
"strings"
)
type ISettings interface {
CacheAddr() string
CacheDB() int
CachePassword() string
CacheUseTLS() bool
DatabaseURI() string
Database() string
StoreBlockchain() string
StoreAddress() string
StoreImageURI() string
// This ethereum uri should be used for most workflows.
EthereumMainURI() string
// This ethereum secondary uri is intended to offload traffic from the main uri and avoid rate limiting for critical paths.
// this URI should be used sparringly for critical workflows.
EthereumSecondaryURI() string
PolygonMainURI() string
ArbitrumMainURI() string
OptimismMainURI() string
ENSMetadataURI() string
// This ethereum uri is specific to alchemy and is intended for alchemy only apis (e.g. get all nfts).
AlchemyEthereumURI() string
CryptoKittiesMetadataURI() string
IPFSURI() string
TheGraphURI() string
TheGraphHostedURI() string
DefaultTokenAddresses() []string
SpotlightProfileAddress() string
}
type settings struct {
redisAddr string
redisDB string
redisPassword string
redisUseTLS string
mongoURI string
mongoDB string
storeBlockchain string
storeAddress string
storeImageURI string
ethereumMainURI string
ethereumSecondaryURI string
polygonMainURI string
arbitrumMainURI string
optimismMainURI string
alchemyEthereumURI string
ensMetadataURI string
cryptoKittiesMetadataURI string
ipfsURI string
theGraphURI string
theGraphHostedURI string
defaultTokenAddresses string
spotlightProfileAddress string
}
func NewSettings() ISettings {
return &settings{
redisAddr: os.Getenv("REDIS_ADDR"),
redisPassword: os.Getenv("REDIS_PASSWORD"),
redisDB: os.Getenv("REDIS_DB"),
redisUseTLS: os.Getenv("REDIS_USE_TLS"),
mongoURI: os.Getenv("MONGO_URI"),
mongoDB: os.Getenv("MONGO_DB"),
storeBlockchain: os.Getenv("STORE_BLOCKCHAIN"),
storeAddress: os.Getenv("STORE_ADDRESS"),
storeImageURI: os.Getenv("STORE_IMAGE_URI"),
ethereumMainURI: os.Getenv("ETHEREUM_MAIN_URI"),
ethereumSecondaryURI: os.Getenv("ETHEREUM_SECONDARY_URI"),
polygonMainURI: os.Getenv("POLYGON_MAIN_URI"),
arbitrumMainURI: os.Getenv("ARBITRUM_MAIN_URI"),
optimismMainURI: os.Getenv("OPTIMISM_MAIN_URI"),
alchemyEthereumURI: os.Getenv("ALCHEMY_ETHEREUM_URI"),
ensMetadataURI: os.Getenv("ENS_METADATA_URI"),
cryptoKittiesMetadataURI: os.Getenv("CRYPTO_KITTIES_METADATA_URI"),
ipfsURI: os.Getenv("IPFS_URI"),
theGraphURI: os.Getenv("THE_GRAPH_URI"),
theGraphHostedURI: os.Getenv("THE_GRAPH_HOSTED_URI"),
defaultTokenAddresses: os.Getenv("DEFAULT_TOKEN_ADDRESSES"),
spotlightProfileAddress: os.Getenv("SPOTLIGHT_PROFILE_ADDRESS"),
}
}
func (s *settings) CacheAddr() string {
return s.redisAddr
}
func (s *settings) CacheDB() int {
redisDB, err := strconv.Atoi(s.redisDB)
if err != nil {
panic(fmt.Errorf("invalid redis db value %v %w", s.redisDB, err))
}
return redisDB
}
func (s *settings) CachePassword() string {
return s.redisPassword
}
func (s *settings) CacheUseTLS() bool {
useTLS, err := strconv.ParseBool(s.redisUseTLS)
if err != nil {
panic(fmt.Errorf("invalid redis use tls value %v %w", s.redisUseTLS, err))
}
return useTLS
}
func (s *settings) DatabaseURI() string {
return s.mongoURI
}
func (s *settings) Database() string {
return s.mongoDB
}
func (s *settings) StoreBlockchain() string {
return s.storeBlockchain
}
func (s *settings) StoreAddress() string {
return s.storeAddress
}
func (s *settings) StoreImageURI() string {
return s.storeImageURI
}
func (s *settings) EthereumMainURI() string {
return s.ethereumMainURI
}
func (s *settings) EthereumSecondaryURI() string {
return s.ethereumSecondaryURI
}
func (s *settings) PolygonMainURI() string {
return s.polygonMainURI
}
func (s *settings) ArbitrumMainURI() string {
return s.arbitrumMainURI
}
func (s *settings) OptimismMainURI() string {
return s.optimismMainURI
}
func (s *settings) AlchemyEthereumURI() string {
return s.alchemyEthereumURI
}
func (s *settings) ENSMetadataURI() string {
return s.ensMetadataURI
}
func (s *settings) CryptoKittiesMetadataURI() string {
return s.cryptoKittiesMetadataURI
}
func (s *settings) IPFSURI() string {
return s.ipfsURI
}
func (s *settings) TheGraphURI() string {
return s.theGraphURI
}
func (s *settings) TheGraphHostedURI() string {
return s.theGraphHostedURI
}
func (s *settings) DefaultTokenAddresses() []string {
return strings.Split(s.defaultTokenAddresses, ",")
}
func (s *settings) SpotlightProfileAddress() string {
return s.spotlightProfileAddress
}