fix config load curl string

This commit is contained in:
eson 2018-12-09 22:25:48 +08:00
parent 5019e46d08
commit 1283154f32
2 changed files with 28 additions and 20 deletions

View File

@ -27,6 +27,7 @@ func (curls *YamlCurls) UnmarshalYAML(unmarshal func(interface{}) error) error {
switch tbuf := buf.(type) { switch tbuf := buf.(type) {
case string: case string:
for _, curlinfo := range parseCurl(tbuf) { for _, curlinfo := range parseCurl(tbuf) {
*curls = append(*curls, curlinfo) *curls = append(*curls, curlinfo)
} }
@ -184,6 +185,8 @@ func parseCurl(curl string) []string {
for _, curlinfo := range strings.Split(string(curldata), "\n") { for _, curlinfo := range strings.Split(string(curldata), "\n") {
result = append(result, strings.Trim(curlinfo, "\r\n ")) result = append(result, strings.Trim(curlinfo, "\r\n "))
} }
default:
result = append(result, strings.Trim(curl, "\r\n "))
} }
return result return result

View File

@ -81,7 +81,6 @@ func NewPersonWithConfig(conf string) *Person {
func splitTasks(conf *Config) []ITask { func splitTasks(conf *Config) []ITask {
var tasks []ITask var tasks []ITask
proxies := (*clinked.CircularLinked)(conf.Proxies) proxies := (*clinked.CircularLinked)(conf.Proxies)
for _, scurl := range conf.Curls { for _, scurl := range conf.Curls {
curl, err := curl2info.ParseRawCURL(scurl) curl, err := curl2info.ParseRawCURL(scurl)
if err != nil { if err != nil {
@ -95,15 +94,16 @@ func splitTasks(conf *Config) []ITask {
switch conf.Mode { switch conf.Mode {
case 0: case 0:
initTask(conf, task, curl) initTask(conf, task, curl)
if proxies != nil {
for _, cnode := range proxies.GetLoopValues() { for _, cnode := range proxies.GetLoopValues() {
proxy := cnode.GetValue().(string) proxy := cnode.GetValue().(string)
log.Println(proxy)
task.AddProxies(proxy) task.AddProxies(proxy)
} }
log.Println(task.GetProxies()) }
tasks = append(tasks, task) tasks = append(tasks, task)
case 1: case 1:
if proxies != nil {
for _, cnode := range proxies.GetLoopValues() { for _, cnode := range proxies.GetLoopValues() {
proxy := cnode.GetValue().(string) proxy := cnode.GetValue().(string)
@ -123,6 +123,7 @@ func splitTasks(conf *Config) []ITask {
} }
} }
} }
}
return tasks return tasks
} }
@ -132,13 +133,17 @@ func (person *Person) Execute() {
taskLen := len(person.Tasks) taskLen := len(person.Tasks)
result := make(chan string, 1) result := make(chan string, 1)
log.Println(person.Tasks)
for _, task := range person.Tasks { for _, task := range person.Tasks {
go ExecuteOnPlan(task, result) go ExecuteOnPlan(task, result)
} }
for t := range result { for t := range result {
log.Println(t) log.Println(t)
taskLen-- taskLen--
if taskLen <= 0 { if taskLen <= 0 {
close(result) close(result)
} }