-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
78 lines (65 loc) · 1.32 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
69
70
71
72
73
74
75
76
77
78
package config
import (
"fmt"
"io/ioutil"
"os"
"github.com/sirupsen/logrus"
"github.com/wrfly/ecp"
yaml "gopkg.in/yaml.v2"
"github.com/wrfly/yasuser/utils"
)
type SrvConfig struct {
Domain string `default:"https://u.kfd.me"`
Port int `default:"8084"`
Limit int64 `default:"10"`
Pprof bool `default:"false"`
GAID string `default:"62244864-8"`
}
type StoreConfig struct {
DBPath string `default:"./yasuser.db"`
DBType string `default:"bolt"`
Redis string `default:"redis://localhost:6379"`
}
type list struct {
WhiteList []string
BlackList []string
}
type Filter struct {
Domain list
Keyword list
}
type Config struct {
Debug bool `default:"false"`
Auth string `default:"password"`
Store StoreConfig
Server SrvConfig
Filter Filter
}
func New() *Config {
return &Config{}
}
func (c *Config) Parse(filePath string) {
if filePath == "" {
return
}
f, err := os.Open(filePath)
if err != nil {
logrus.Fatal(utils.AddLineNum(err))
}
bs, err := ioutil.ReadAll(f)
if err != nil {
logrus.Fatal(utils.AddLineNum(err))
}
err = yaml.Unmarshal(bs, c)
if err != nil {
logrus.Fatal(utils.AddLineNum(err))
}
}
func (c *Config) Example() {
ecp.Default(c)
bs, err := yaml.Marshal(*c)
if err != nil {
logrus.Fatalf("marshal yaml error: %s", utils.AddLineNum(err))
}
fmt.Printf("%s", bs)
}