-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.go
44 lines (37 loc) · 829 Bytes
/
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
package main
import (
. "github.com/jelder/goenvmap"
"log"
)
type Config struct {
Secret string
ListenAddress string
TargetURLs []string
HerokuAuthToken string
}
var (
config Config
)
func init() {
ENV = MustLoadEnv()
config.Secret = getSecret()
config.ListenAddress = getListenAddress()
config.HerokuAuthToken = getHerokuAuthToken()
}
func getHerokuAuthToken() (authToken string) {
authToken = ENV["HEROKU_AUTH_TOKEN"]
if authToken == "" {
log.Fatal("HEROKU_AUTH_TOKEN is not set; cannot fetch your Heroku apps' ENV vars")
}
return authToken
}
func getSecret() (secret string) {
secret = ENV["SECRET_KEY"]
if len(secret) < 30 {
log.Fatal("SECRET_KEY is much too short; refusing to use it.")
}
return secret
}
func getListenAddress() string {
return ":" + ENV.Get("PORT", "8080")
}