-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
44 lines (36 loc) · 801 Bytes
/
config.go
File metadata and controls
44 lines (36 loc) · 801 Bytes
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 (
"encoding/json"
"io/ioutil"
"log"
"github.com/gin-gonic/gin"
)
type NoteAppConfig struct {
HealthCheckTime int
DBDriver string
DBConfig map[string]string
ReleaseMode string
}
func readConfig(configFile string) (*NoteAppConfig, error) {
file, err := ioutil.ReadFile(configFile)
if err != nil {
return &NoteAppConfig{
DBDriver: "redis",
DBConfig: map[string]string{},
ReleaseMode: gin.DebugMode,
}, err
}
config := &NoteAppConfig{}
json.Unmarshal(file, config)
if config.DBDriver == "" {
log.Println("Use redis as default")
config.DBDriver = "redis"
}
if config.DBConfig == nil {
config.DBConfig = map[string]string{}
}
if config.ReleaseMode == "" {
config.ReleaseMode = gin.DebugMode
}
return config, err
}