-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
75 lines (65 loc) · 2.56 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
73
74
75
package main
import (
"encoding/json"
"os"
"github.com/getsentry/raven-go"
"github.com/kpango/glg"
)
// EnvConfig specifies all of the configuration that needs to be setup on different hosts or
// for different environments. This includes things like log leve, SSL config, Redis,
// and the Database which stores the Destiny manifest.
type EnvConfig struct {
Environment string `json:"environment"`
RedisURL string `json:"redis_url"`
BungieAPIKey string `json:"bungie_api_key"`
DatabaseURL string `json:"database_url"`
AlexaAppID string `json:"alexa_app_id"`
WarmindNetworkAlexaAppID string `json:"warmind_network_alexa_app_id"`
WarmindBungieAPIKey string `json:"warmind_bungie_api_key"`
LogLevel string `json:"log_level"`
LogFilePath string `json:"log_file_path"`
SSLCertPath string `json:"ssl_cert_path"`
SSLKeyPath string `json:"ssl_key_path"`
Port string `json:"port"`
SentryDSN string `json:"sentry_dsn"`
DebugAlexaRequests bool `json:"debug_alexa_requests"`
DebugGoogleRequests bool `json:"debug_google_requests"`
}
// NewEnvConfig will create a default instance of the EnvConfig struct
func NewEnvConfig() *EnvConfig {
// Default to values from the environment or nothing, this is mainly for the Heroku deployments
config := &EnvConfig{
Environment: "staging",
RedisURL: os.Getenv("REDIS_URL"),
BungieAPIKey: os.Getenv("BUNGIE_API_KEY"),
WarmindBungieAPIKey: os.Getenv("WARMIND_BUNGIE_API_KEY"),
DatabaseURL: os.Getenv("DATABASE_URL"),
AlexaAppID: os.Getenv("ALEXA_APP_ID"),
WarmindNetworkAlexaAppID: os.Getenv("WARMIND_NETWORK_APP_ID"),
LogLevel: os.Getenv("GUARDIAN_HELPER_LOG_LEVEL"),
Port: os.Getenv("PORT"),
SentryDSN: os.Getenv("SENTRY_DSN"),
DebugAlexaRequests: os.Getenv("DEBUG_ALEXA_REQUESTS") != "",
DebugGoogleRequests: os.Getenv("DEBUG_GOOGLE_REQUESTS") != "",
}
return config
}
func loadConfig(path *string) (config *EnvConfig) {
config = NewEnvConfig()
if *path == "" {
return
}
in, err := os.Open(*path)
if err != nil {
raven.CaptureError(err, nil)
glg.Errorf("Error trying to open the specified config file: %s", err.Error())
return
}
err = json.NewDecoder(in).Decode(&config)
if err != nil {
raven.CaptureError(err, nil)
glg.Errorf("Error deserializing config JSON: %s", err.Error())
return
}
return
}