-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
71 lines (63 loc) · 1.42 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
70
71
package core
import (
"fmt"
"github.com/spf13/viper"
"log"
"sync"
)
var (
once sync.Once
Conf = &conf{}
)
type conf struct {
DB DBConf
Redis RedisConf
App SettingConf
Zaplog ZapLogConf
}
type DBConf struct {
DBType string
DBUser string
DBPwd string
DBHost string
DBName string
}
type RedisConf struct {
RedisAddr string
RedisPWD string
RedisDB int
}
type SettingConf struct {
HttpPort int `json:"http-port"`
ReadTimeout int `json:"read-timeout"`
WriteTimeout int `json:"write-timeout"`
RunMode string
PageSize int
JwtSecret string
UploadTmpDir string
ImgSavePath string
ImgUrlPath string
}
type ZapLogConf struct {
Level string `json:"level" yaml:"level"`
Format string ` json:"format" yaml:"format"`
Prefix string ` json:"prefix" yaml:"prefix"`
Director string ` json:"director" yaml:"director"`
LinkName string ` json:"linkName" yaml:"link-name"`
ShowLine bool ` json:"showLine" yaml:"showLine"`
EncodeLevel string ` json:"encodeLevel" yaml:"encode-level"`
StacktraceKey string `json:"stacktraceKey" yaml:"stacktrace-key"`
LogInConsole bool `json:"logInConsole" yaml:"log-in-console"`
}
func InitConfig(tomlPath string) {
once.Do(func() {
v := viper.New()
v.SetConfigFile(tomlPath)
err := v.ReadInConfig()
if err != nil {
log.Fatal("read config failed: %v", err)
}
v.Unmarshal(&Conf)
fmt.Println(Conf)
})
}