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 }