-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.go
43 lines (36 loc) · 865 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
package globals
import (
"encoding/json"
"log"
"os"
)
type GlobalConfig struct {
AppPort int `json:"app_port"`
DbName string `json:"db_name"`
DbUser string `json:"db_user"`
DbPassword string `json:"db_password"`
RedisPort int `json:"redis_port"`
RedisPassword string `json:"redis_password"`
JudgeSigKey string `json:"judge_sig_key"`
CookieKeyPairs []string `json:"cookie_key_pairs"`
ApiPrefix string `json:"api_prefix"`
}
var configInitialized = false
var config GlobalConfig
func LoadConfiguration(file string) GlobalConfig {
var c GlobalConfig
f, err := os.Open(file)
defer f.Close()
if err != nil {
log.Fatalln(err)
}
decoder := json.NewDecoder(f)
decoder.Decode(&c)
return c
}
func Config() *GlobalConfig {
if !configInitialized {
config = LoadConfiguration("config.json")
}
return &config
}