-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconf.go
57 lines (48 loc) · 1.3 KB
/
conf.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
package main
import (
"io/ioutil"
"gopkg.in/yaml.v2"
)
var Conf = &struct {
Log LogConf `yaml:"log"`
Beanstalk BeanstalkConf `yaml:"beanstalk"`
Chrome ChromeConf `yaml:"chrome"`
Task TaskConf `yaml:"task"`
}{}
type LogConf struct {
Dir string `yaml:"dir"`
Level string `yaml:"level"`
}
type BeanstalkConf struct {
Host string `yaml:"host"`
Port int `yaml:"port"`
ReserveTube string `yaml:"reserve_tube"`
ReserveTimeout int `yaml:"reserve_timeout"`
PutTube string `yaml:"put_tube"`
PutPriority int `yaml:"put_priority"`
PutDelay int `yaml:"put_delay"`
PutTTR int `yaml:"put_ttr"`
Heartbeat int `yaml:"heartbeat"`
}
type ChromeConf struct {
Windows Chrome `yaml:"windows"`
Linux Chrome `yaml:"linux"`
}
type Chrome struct {
Exec string `yaml:"exec"`
Args []string `yaml:"args"`
}
type TaskConf struct {
PollingInterval int `yaml:"polling_interval"`
Rules string `yaml:"rules"`
CrawlDuration int `yaml:"crawl_duration"`
CrawlRetry int `yaml:"crawl_retry"`
CrawlTimeout int `yaml:"crawl_timeout"`
}
func LoadConf(file string) error {
data, e := ioutil.ReadFile(file)
if e != nil {
return e
}
return yaml.Unmarshal(data, Conf)
}