From 7faea797d00aa2af6ed96615b6346b87833e3d17 Mon Sep 17 00:00:00 2001
From: huangsimin <huangsimin@youmi.net>
Date: Thu, 24 Jan 2019 18:17:40 +0800
Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E6=AD=A5=E7=BB=93=E6=9E=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 base.go        | 19 +++++++++++
 config.go      |  1 +
 config_test.go | 85 ++++++++++++++++++++++++++++++++++++++++++++++++++
 task.go        |  1 +
 task_test.go   |  1 +
 5 files changed, 107 insertions(+)
 create mode 100644 base.go
 create mode 100644 config.go
 create mode 100644 config_test.go
 create mode 100644 task.go
 create mode 100644 task_test.go

diff --git a/base.go b/base.go
new file mode 100644
index 0000000..0461cb9
--- /dev/null
+++ b/base.go
@@ -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
+}
diff --git a/config.go b/config.go
new file mode 100644
index 0000000..71a1702
--- /dev/null
+++ b/config.go
@@ -0,0 +1 @@
+package simulator
diff --git a/config_test.go b/config_test.go
new file mode 100644
index 0000000..0615617
--- /dev/null
+++ b/config_test.go
@@ -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
+}
diff --git a/task.go b/task.go
new file mode 100644
index 0000000..71a1702
--- /dev/null
+++ b/task.go
@@ -0,0 +1 @@
+package simulator
diff --git a/task_test.go b/task_test.go
new file mode 100644
index 0000000..71a1702
--- /dev/null
+++ b/task_test.go
@@ -0,0 +1 @@
+package simulator