-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
67 lines (58 loc) · 1.28 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
package config
import (
"gopkg.in/yaml.v3"
"log"
"os"
)
var Conf *conf
type db struct {
Host string `yaml:"host"`
Port string `yaml:"port"`
Name string `yaml:"name"`
Pass string `yaml:"pass"`
DB string `yaml:"db"`
}
type app struct {
Version string `yaml:"version"`
Env string `yaml:"env"`
Name string `yaml:"name"`
Desc string `yaml:"desc"`
Keywords string `yaml:"keywords"`
VisitMode string `yaml:"visitMode"`
}
type session struct {
Name string `yaml:"name"`
Secret string `yaml:"secret"`
}
type upload struct {
Path string `yaml:"path"`
ImageExt []string `yaml:"imageExt"`
AvatarFileSize int64 `yaml:"avatarFileSize"`
TopicFileSize int64 `yaml:"topicFileSize"`
}
type redis struct {
Host string `yaml:"host"`
Port string `yaml:"port"`
Pass string `yaml:"pass"`
DB string `yaml:"db"`
IdleTimeout string `yaml:"idleTimeout"`
}
type conf struct {
App app `yaml:"apps"`
DB db `yaml:"db"`
Session session `yaml:"session"`
Upload upload `yaml:"upload"`
Redis redis `yaml:"redis"`
}
func init() {
b, err := os.ReadFile("config/config.yaml")
if err != nil {
log.Fatal(err)
}
var c *conf
err = yaml.Unmarshal(b, &c)
if err != nil {
log.Fatal(err)
}
Conf = c
}