-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfig.go
More file actions
70 lines (62 loc) · 1.63 KB
/
config.go
File metadata and controls
70 lines (62 loc) · 1.63 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main
import (
"errors"
"os"
_ "github.com/joho/godotenv/autoload"
)
const (
envMatrixUsername = "MATRIX_USERNAME"
envMatrixPassword = "MATRIX_PASSWORD"
envMatrixServer = "MATRIX_SERVER"
envGoogleAPIKey = "GOOGLE_API_KEY"
envGoogleCX = "GOOGLE_CX"
envWeatherAPIKey = "WEATHER_API_KEY"
envWebhookAddr = "WEBHOOK_ADDR"
envTenorAPIKey = "TENOR_API_KEY"
)
const (
defaultMatrixServer = "https://matrix-client.matrix.org"
defaultWebhookPort = "8080"
)
type Config struct {
MatrixServer string
MatrixUsername string
MatrixPassword string
GoogleAPIKey string
GoogleCX string
WeatherAPIKey string
WebhookAddr string
TenorAPIKey string
}
func NewConfig() (*Config, error) {
matrixServer := os.Getenv(envMatrixServer)
if matrixServer == "" {
matrixServer = defaultMatrixServer
}
matrixUsername := os.Getenv(envMatrixUsername)
if matrixUsername == "" {
return nil, errors.New("MATRIX_USERNAME not set")
}
matrixPassword := os.Getenv(envMatrixPassword)
if matrixPassword == "" {
return nil, errors.New("MATRIX_PASSWORD not set")
}
webhookAddr := os.Getenv(envWebhookAddr)
if webhookAddr == "" {
webhookAddr = ":" + defaultWebhookPort
}
tenorAPIKey := os.Getenv(envTenorAPIKey)
googleAPIKey := os.Getenv(envGoogleAPIKey)
googleCX := os.Getenv(envGoogleCX)
openWeatherAPIKey := os.Getenv(envWeatherAPIKey)
return &Config{
MatrixServer: matrixServer,
MatrixUsername: matrixUsername,
MatrixPassword: matrixPassword,
GoogleAPIKey: googleAPIKey,
GoogleCX: googleCX,
WeatherAPIKey: openWeatherAPIKey,
WebhookAddr: webhookAddr,
TenorAPIKey: tenorAPIKey,
}, nil
}