generated from xiachufang/go-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathconfig.go
More file actions
82 lines (70 loc) · 1.49 KB
/
config.go
File metadata and controls
82 lines (70 loc) · 1.49 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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
Tilde *TildeConf
}
// 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
}
// TildeConf is config of tilde-enhanced
type TildeConf struct {
Search *TildeSearchConf
Theme string
ShowKeys bool `yaml:"show_keys"`
}
// TildeSearchConf search config for tilde
type TildeSearchConf struct {
URL string
Placeholder 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
}