From 1283154f327e6b076db832c9d69214f37e94881c Mon Sep 17 00:00:00 2001 From: eson <474420502@qq.com> Date: Sun, 9 Dec 2018 22:25:48 +0800 Subject: [PATCH] fix config load curl string --- config.go | 3 +++ person.go | 45 +++++++++++++++++++++++++-------------------- 2 files changed, 28 insertions(+), 20 deletions(-) diff --git a/config.go b/config.go index beaf14e..c379b98 100644 --- a/config.go +++ b/config.go @@ -27,6 +27,7 @@ func (curls *YamlCurls) UnmarshalYAML(unmarshal func(interface{}) error) error { switch tbuf := buf.(type) { case string: + for _, curlinfo := range parseCurl(tbuf) { *curls = append(*curls, curlinfo) } @@ -184,6 +185,8 @@ func parseCurl(curl string) []string { for _, curlinfo := range strings.Split(string(curldata), "\n") { result = append(result, strings.Trim(curlinfo, "\r\n ")) } + default: + result = append(result, strings.Trim(curl, "\r\n ")) } return result diff --git a/person.go b/person.go index 8984fb9..ae4014a 100644 --- a/person.go +++ b/person.go @@ -81,7 +81,6 @@ func NewPersonWithConfig(conf string) *Person { func splitTasks(conf *Config) []ITask { var tasks []ITask proxies := (*clinked.CircularLinked)(conf.Proxies) - for _, scurl := range conf.Curls { curl, err := curl2info.ParseRawCURL(scurl) if err != nil { @@ -95,31 +94,33 @@ func splitTasks(conf *Config) []ITask { switch conf.Mode { case 0: initTask(conf, task, curl) - for _, cnode := range proxies.GetLoopValues() { - proxy := cnode.GetValue().(string) - log.Println(proxy) - task.AddProxies(proxy) + if proxies != nil { + for _, cnode := range proxies.GetLoopValues() { + proxy := cnode.GetValue().(string) + task.AddProxies(proxy) + } } - log.Println(task.GetProxies()) + tasks = append(tasks, task) case 1: + if proxies != nil { + for _, cnode := range proxies.GetLoopValues() { + proxy := cnode.GetValue().(string) - for _, cnode := range proxies.GetLoopValues() { - proxy := cnode.GetValue().(string) + ncurl, err := curl2info.ParseRawCURL(scurl) + if err != nil { + panic(err) + } - ncurl, err := curl2info.ParseRawCURL(scurl) - if err != nil { - panic(err) + if curl.ITask == "" { + curl.ITask = conf.ITask + } + ptask := makeRegisterType(ncurl.ITask).(ITask) + initTask(conf, ptask, ncurl) + + ptask.AddProxies(proxy) + tasks = append(tasks, ptask) } - - if curl.ITask == "" { - curl.ITask = conf.ITask - } - ptask := makeRegisterType(ncurl.ITask).(ITask) - initTask(conf, ptask, ncurl) - - ptask.AddProxies(proxy) - tasks = append(tasks, ptask) } } } @@ -132,13 +133,17 @@ func (person *Person) Execute() { taskLen := len(person.Tasks) result := make(chan string, 1) + log.Println(person.Tasks) for _, task := range person.Tasks { + go ExecuteOnPlan(task, result) + } for t := range result { log.Println(t) taskLen-- + if taskLen <= 0 { close(result) }