初步结构
This commit is contained in:
commit
7faea797d0
19
base.go
Normal file
19
base.go
Normal file
|
@ -0,0 +1,19 @@
|
|||
package simulator
|
||||
|
||||
import "log"
|
||||
|
||||
// must 处理err, 失败后panic
|
||||
func must(err error) {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// notMust 处理err, 失败后返回
|
||||
func notMust(err error) bool {
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
85
config_test.go
Normal file
85
config_test.go
Normal file
|
@ -0,0 +1,85 @@
|
|||
package simulator
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// ADInfo ad 的一些属性,基础信息等
|
||||
type ADInfo struct {
|
||||
Priority int `yaml:"priority"`
|
||||
Device string `yaml:"device"`
|
||||
Platform string `yaml:"platform"`
|
||||
AreaCC string `yaml:"area_cc"`
|
||||
Channel int `yaml:"channel"`
|
||||
Media int `yaml:"media"`
|
||||
SpiderID int `yaml:"spider_id"`
|
||||
CatchAccountID int `yaml:"catch_account_id"`
|
||||
}
|
||||
|
||||
type CurlInfo struct {
|
||||
TakeType int
|
||||
Address string
|
||||
URI string
|
||||
}
|
||||
|
||||
type ProxySetting struct {
|
||||
Mode int `yaml:"mode"`
|
||||
Proxies []string `yaml:"proxies"`
|
||||
}
|
||||
|
||||
type SpiderSetting struct {
|
||||
// Mode int `yaml:"mode"`
|
||||
// Proxies *YamlProxies `yaml:"proxies"`
|
||||
Retry int `yaml:"retry"`
|
||||
Crontab string `yaml:"crontab"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
ProxySetting `yaml:",inline"`
|
||||
SpiderSetting `yaml:",inline"`
|
||||
|
||||
ADInfo `yaml:",inline"`
|
||||
}
|
||||
|
||||
// NewConfig 加载并返回Config
|
||||
func NewConfig(p string) *Config {
|
||||
// f, err := os.Open(p)
|
||||
// defer f.Close()
|
||||
// if err != nil {
|
||||
// panic(err)
|
||||
// }
|
||||
|
||||
f := strings.NewReader(p)
|
||||
conf := &Config{
|
||||
|
||||
ProxySetting: ProxySetting{
|
||||
Mode: 0,
|
||||
Proxies: []string{},
|
||||
},
|
||||
|
||||
SpiderSetting: SpiderSetting{
|
||||
Retry: 1,
|
||||
Crontab: "",
|
||||
},
|
||||
|
||||
ADInfo: ADInfo{
|
||||
Device: "",
|
||||
Platform: "",
|
||||
AreaCC: "",
|
||||
Channel: -1,
|
||||
Media: -1,
|
||||
SpiderID: -1,
|
||||
CatchAccountID: -1,
|
||||
},
|
||||
}
|
||||
|
||||
err := yaml.NewDecoder(f).Decode(conf)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return conf
|
||||
}
|
1
task_test.go
Normal file
1
task_test.go
Normal file
|
@ -0,0 +1 @@
|
|||
package simulator
|
Loading…
Reference in New Issue
Block a user