-
Notifications
You must be signed in to change notification settings - Fork 125
/
config.go
69 lines (58 loc) · 1.58 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
package googlekeepclone
import (
"fmt"
"log"
"net/url"
"os"
)
// AppConfig holds the configuration for the application
type AppConfig struct {
IsProd bool
AppHost *url.URL
DBFile string
StaticDir string
CookieStoreKey string
SessionStoreKey string
SessionCookieName string
}
// DefaultAppConfig creates an instance of AppConfig and populates with default/environment values
func DefaultAppConfig() *AppConfig {
production := os.Getenv("PRODUCTION")
host := os.Getenv("HOST")
if host == "" {
log.Fatal("The environment variable HOST doesn't exist")
}
port := os.Getenv("PORT")
if port == "" {
log.Fatal("The environment variable PORT doesn't exist")
}
appHost, err := url.Parse(fmt.Sprintf("%s:%s", host, port))
if err != nil {
log.Fatal("The environmental variable HOST or PORT is malformed")
}
cookieStoreKey := os.Getenv("COOKIE_STORE_KEY")
if cookieStoreKey == "" {
log.Fatal("The environment variable COOKIE_STORE_KEY doesn't exist")
}
sessionStoreKey := os.Getenv("SESSION_STORE_KEY")
if sessionStoreKey == "" {
log.Fatal("The environment variable SESSION_STORE_KEY doesn't exist")
}
dbFile := os.Getenv("DB_FILE")
if dbFile == "" {
dbFile = "keepclone.db"
}
staticDir := os.Getenv("STATIC_DIR")
if staticDir == "" {
staticDir = "./web/build/"
}
return &AppConfig{
IsProd: production != "",
AppHost: appHost,
DBFile: dbFile,
StaticDir: staticDir,
CookieStoreKey: cookieStoreKey,
SessionStoreKey: sessionStoreKey,
SessionCookieName: "gkc_session",
}
}