forked from zxysilent/blog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
62 lines (57 loc) · 1.16 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
package conf
import (
"encoding/xml"
"log"
"os"
)
var (
// Name 姓名
Name string
// Debug Debug
Debug bool
// Conn 连接字符串
Conn string
// Addr Addr
Addr string
MaxIdle int
MaxOpen int
ShowSQLl bool
UseCache bool
CacheCount int
)
// config config
type config struct {
Name string `xml:"name"`
Depict string `xml:"depict"`
Debug bool `xml:"debug"`
Conn string `xml:"conn"`
Addr string `xml:"addr"`
MaxIdle int `xml:"max-idle"`
MaxOpen int `xml:"max-open"`
ShowSQLl bool `xml:"show-sql"`
UseCache bool `xml:"use-cache"`
CacheCount int `xml:"cache-count"`
}
func init() {
var conf config
// 读取配置文件
xmlRaw, err := os.Open("./conf/conf.xml")
if err != nil {
log.Fatalln("配置文件读取失败", err.Error())
}
decoder := xml.NewDecoder(xmlRaw)
err = decoder.Decode(&conf)
if err != nil {
log.Fatalln("配置文件无效", err.Error())
}
xmlRaw.Close()
Name = conf.Name
Debug = conf.Debug
Conn = conf.Conn
Addr = conf.Addr
MaxIdle = conf.MaxIdle
MaxOpen = conf.MaxOpen
ShowSQLl = conf.ShowSQLl
UseCache = conf.UseCache
CacheCount = conf.CacheCount
}