/
config.go
58 lines (54 loc) · 1.25 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
package config
import (
"io/ioutil"
"gopkg.in/yaml.v2"
)
// Config 配置
type Config struct {
File string
Log int `yaml:"log"`
Server struct {
ID int64 `yaml:"id"`
Host string `yaml:"host"`
Port int `yaml:"port"`
JWTSecret string `yaml:"secret"`
Expire int64 `yaml:"expire"`
}
Mysql struct {
Host string `yaml:"host"`
Port string `yaml:"port"`
User string `yaml:"user"`
Password string `yaml:"password"`
Database string `yaml:"database"`
MaxIdleConns int `yaml:"max_idle_conns"`
MaxOpenConns int `yaml:"max_open_conns"`
MaxLifeTime int64 `yaml:"max_life_time"`
ShowSQL bool `yaml:"show_sql"`
Sync bool `yaml:"sync"`
UseCache bool `yaml:"use_cache"`
}
Cache string `yaml:"cache"`
Memory struct {
Size int `yaml:"size"`
}
Redis struct {
Host string `yaml:"host"`
Password string `yaml:"password"`
Port int `yaml:"port"`
DB int `yaml:"db"`
}
}
// Load 加载
func Load(file string) (*Config, error) {
data, err := ioutil.ReadFile(file)
if err != nil {
return nil, err
}
var config Config
err = yaml.Unmarshal(data, &config)
if err != nil {
return nil, err
}
config.File = file
return &config, nil
}