forked from adtac/commento
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
40 lines (34 loc) · 1.06 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
package main
import (
"github.com/joho/godotenv"
"os"
"strings"
)
func loadConfig() error {
// Default value for each environment variable.
env := map[string]string{
"COMMENTO_DATABASE_FILE": "sqlite3.db",
"COMMENTO_PORT": "8080",
}
// Load configuration from the environment. Final value is governed by the
// last config file setting the variable. For example, a COMMENTO_PORT
// value in .env.development.local will be used even if COMMENTO_PORT
// exists in a .env.development file
files := []string{".env.development.local", ".env.test.local", ".env.production.local", ".env.local", ".env.development", ".env.test", ".env.production", ".env"}
for _, file := range files {
newEnv, err := godotenv.Read(file)
if err == nil {
for key, value := range newEnv {
key = strings.TrimSpace(key)
value = strings.TrimSpace(value)
env[key] = value
}
}
}
// TODO: Add configuration verification. This could potentially make
// loadConfig return a non-nil error.
for key, value := range env {
os.Setenv(key, value)
}
return nil
}