/
config.go
56 lines (49 loc) · 1.12 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
package common
import (
"gopkg.in/ini.v1"
)
// Config config
type Config struct {
Common `ini:"common"`
Server `ini:"server"`
Redis `ini:"redis"`
Log `ini:"log"`
}
// Common config
type Common struct {
DataFolder string `ini:"dataFolder"`
Repo string `ini:"repo"`
}
// Server config
type Server struct {
Port int `ini:"port"`
Mode string `ini:"mode"`
StaticPath string `ini:"staticPath"`
}
// Server config
type Log struct {
LogFilePath string `ini:"logFilePath"`
LogFileName string `ini:"logFileName"`
LogLevel int `ini:"logLevel"`
LogOutput string `ini:"logOutput"`
}
// Redis config
type Redis struct {
Host string `ini:"host"`
DB int `ini:"db"`
CachePrefix string `ini:"cachePrefix"`
SortedPrefix string `ini:"sortedPrefix"`
}
// InitConfig read config from file
func InitConfig(configFileMame string) (*Config, error) {
cfg, err := ini.Load(configFileMame)
if err != nil {
return nil, err
}
config := new(Config)
err = cfg.MapTo(&config)
if err != nil {
return nil, err
}
return config, nil
}