-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconfig.go
72 lines (58 loc) · 1.32 KB
/
config.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
package main
import (
"fmt"
"os"
)
const (
envAddress = "ADDRESS"
envPort = "PORT"
envNodeAPI = "VOLTAGE_NODE_API"
//nolint:gosec
envWebhookSecret = "VOLTAGE_WEBHOOK_SECRET"
envWalletPassword = "VOLTAGE_WALLET_PASSWORD"
)
type missingVariableError struct {
name string
}
func (e missingVariableError) String() string {
return fmt.Sprintf("missing environment variable %s", e.name)
}
func (e missingVariableError) Error() string {
return e.String()
}
type config struct {
address string
nodeAPI string
walletPassword string
webhookSecret string
}
func newConfig() (*config, error) {
secret := os.Getenv(envWebhookSecret)
if secret == "" {
return nil, missingVariableError{envWebhookSecret}
}
nodeAPI := os.Getenv(envNodeAPI)
if nodeAPI == "" {
return nil, missingVariableError{envNodeAPI}
}
walletPassword := os.Getenv(envWalletPassword)
if walletPassword == "" {
return nil, missingVariableError{envWalletPassword}
}
address := getAddressFromEnv()
return &config{
address: address,
nodeAPI: nodeAPI,
walletPassword: walletPassword,
webhookSecret: secret,
}, nil
}
func getAddressFromEnv() string {
if address := os.Getenv(envAddress); address != "" {
return address
}
if port := os.Getenv(envPort); port != "" {
return ":" + port
}
return ":8080"
}