From 0b50b2f5410b955f9b1ee4dd751fc7e52b02a8e0 Mon Sep 17 00:00:00 2001 From: eson <474420502@qq.com> Date: Fri, 21 Dec 2018 19:02:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E6=97=A0=E6=95=88curl?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.go | 15 ++++++++++++--- task_test.go | 8 ++------ test.yaml | 2 +- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/config.go b/config.go index 5feb1f8..7c2b934 100644 --- a/config.go +++ b/config.go @@ -182,7 +182,10 @@ func parseCurl(curl string) []string { curldata, err := ioutil.ReadAll(curlfile) for _, curlinfo := range strings.Split(string(curldata), "\n") { - result = append(result, strings.Trim(curlinfo, "\r\n ")) + curlstr := strings.Trim(curlinfo, "\r\n ") + if len(curlstr) >= 4 { + result = append(result, curlstr) + } } case '#': @@ -195,10 +198,16 @@ func parseCurl(curl string) []string { panic(err) } for _, curlinfo := range strings.Split(string(curldata), "\n") { - result = append(result, strings.Trim(curlinfo, "\r\n ")) + curlstr := strings.Trim(curlinfo, "\r\n ") + if len(curlstr) >= 4 { + result = append(result, curlstr) + } } default: - result = append(result, strings.Trim(curl, "\r\n ")) + curlstr := strings.Trim(curl, "\r\n ") + if len(curlstr) >= 4 { + result = append(result, curlstr) + } } return result diff --git a/task_test.go b/task_test.go index d143592..2f14767 100644 --- a/task_test.go +++ b/task_test.go @@ -10,12 +10,9 @@ import ( func TestExecute(t *testing.T) { curl := `curl 'https://appgrowing.cn/' -H 'authority: appgrowing.cn' -H 'cache-control: max-age=0' -H 'upgrade-insecure-requests: 1' -H 'user-agent: Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1' -H 'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8' -H 'accept-encoding: gzip, deflate, br' -H 'accept-language: zh' -H 'cookie: _ga=GA1.2.1371058419.1533104518; _gid=GA1.2.896241740.1543307916; _gat_gtag_UA_4002880_19=1' -H 'if-none-match: W/"5bf7a0a9-ca6"' -H 'if-modified-since: Fri, 23 Nov 2018 06:39:37 GMT' --compressed` - u, err := curl2info.ParseRawCURL(curl) - if err != nil { - panic(err) - } + u := curl2info.ParseRawCURL(curl) - _, err = u.CreateWorkflow(nil).Execute() + _, err := u.CreateWorkflow(nil).Execute() if err != nil { t.Error("TestExecute") } @@ -41,7 +38,6 @@ func TestExecutePlan(t *testing.T) { person := NewPerson() person.Config("test.yaml") person.Execute() - // for _, task := range person.Tasks.GetLoopValues() { // task.GetValue().(*Task).ExecuteOnPlan() // } diff --git a/test.yaml b/test.yaml index 3f50a7d..84e0d6f 100644 --- a/test.yaml +++ b/test.yaml @@ -6,7 +6,7 @@ timeout: 12 priority : 10000 # curls: "@test.curl" // 支持, 列表 与 单项字符串 -curls : "@test.curl" +curls : "@test2.curl" task: "toutiao" # next_do : "doothers"