generated from xiachufang/go-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 18
/
config.go
68 lines (58 loc) · 1.21 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
68
package gena
import (
"io/ioutil"
"path/filepath"
"gopkg.in/yaml.v2"
)
// Config is struct of gena's config
type Config struct {
Title string
Description string
Template string
URL string
Logo string
Favicon string
Github string
Footer string
Content *Content
GoogleAnalytics string `yaml:"google_analytics"`
WebStack *WebStackConf
}
// Content is struct of categories
type Content struct {
Categories []*Category
}
// Category struct
type Category struct {
Name string
Sites []*Site
}
// Site struct
type Site struct {
Name string
Description string
URL string
Icon string // 网站图标
}
// WebStackConf is config of webstack
type WebStackConf struct {
Search *WebStackSearchConf
}
// WebStackSearchConf search engine config
type WebStackSearchConf struct {
Enabled bool
Default string
Engines []string
}
// ParseConfig parse config from file
func ParseConfig(file string) (*Config, error) {
buf, err := ioutil.ReadFile(filepath.Clean(file))
if err != nil {
return nil, err
}
cfg := &Config{}
if err := yaml.Unmarshal(buf, cfg); err != nil {
return nil, err
}
return cfg, nil
}