-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathconfig_embed.go
66 lines (53 loc) · 1.36 KB
/
config_embed.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
//go:build embed
// +build embed
/*
* @Description:
* @Author: gphper
* @Date: 2021-07-29 19:47:42
*/
package configs
import (
"bytes"
_ "embed"
"fmt"
"gopkg.in/yaml.v2"
)
type AppConf struct {
Mysql MysqlConf `yaml:"mysql" json:"mysql"`
Redis RedisConf `yaml:"redis" json:"redis"`
Session SessionConf `yaml:"session" json:"session"`
Base BaseConf `yaml:"base" json:"base"`
}
type MysqlConf struct {
Name string `yaml:"name" json:"name"`
Host string `yaml:"host" json:"host"`
Port string `yaml:"port" json:"port"`
UserName string `yaml:"username" json:"username"`
Password string `yaml:"password" json:"password"`
Database string `yaml:"database" json:"database"`
MaxOpenConn int `yaml:"max_open_conn" json:"max_open_conn"`
MaxIdleConn int `yaml:"max_idle_conn" json:"max_idle_conn"`
}
type RedisConf struct {
Addr string `yaml:"addr"`
Db int `yaml:"db"`
Password string `yaml:"password"`
}
type SessionConf struct {
SessionName string `yaml:"session_name"`
}
type BaseConf struct {
Port string `yaml:"port"`
Host string `yaml:"host"`
LogMedia string `yaml:"log_media"`
}
var App = new(AppConf)
//go:embed config.yaml
var iniStr string
//初始化配置文件
func Init() {
err = yaml.Unmarshal(bytes.NewReader([]byte(iniStr)), App)
if err != nil {
fmt.Println(err.Error())
}
}