package imitate import ( "log" "regexp" "testing" "github.com/davecgh/go-spew/spew" "474420502.top/eson/curl2info" ) type Person struct { Tasks *CircularLinked Conf *Config } type Task struct { Curl *curl2info.CURL Plan *CircularLinked Proxies *CircularLinked } func NewPerson(conf string, curlinfo string) *Person { person := &Person{} person.Tasks = NewCircularLinked() person.Conf = NewConfig(conf) if person.Conf.Mode == 0 { for _, scurl := range person.Conf.Curls { curl, err := curl2info.ParseRawCURL(scurl) if err != nil { panic(err) } at := person.Conf.ExecuteAt interval := person.Conf.ExecuteInterval task := NewTask(curl, &at, &interval) switch person.Conf.Mode { case 0: task.Proxies.Append(person.Conf.Proxies) person.Tasks.Append(task) case 1: for _, proxy := range person.Conf.Proxies { curl := &*task.Curl curl.Auth = &*task.Curl.Auth curl.Body = &*task.Curl.Body curl.ParsedURL = &*task.Curl.ParsedURL ptask := NewTask(curl) task.Plan.Clone() } } } } return person } func NewTask(Curl *curl2info.CURL, Plans ...IExecute) *Task { task := &Task{} // task.Conf = NewConfig(conf) task.Curl = Curl task.Plan = NewCircularLinked(Plans) task.Proxies = NewCircularLinked() return task } func TestNewYaml(t *testing.T) { data := spew.Sdump(NewConfig("test.yaml")) if !(regexp.MustCompile(`Device: \(string\) \(len=12\) "eson-OnePlus"`).MatchString(data) && regexp.MustCompile(`Sec: \(int\) 30`).MatchString(data) && regexp.MustCompile(`http://is.snssdk.com/2/article/information/v24/\?`).MatchString(data)) { t.Error(data) } } func TestExecute(t *testing.T) { curl := `curl 'https://re.csdn.net/csdnbi' -H 'Origin: https://blog.csdn.net' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: zh' -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 'Content-Type: text/plain;charset=UTF-8' -H 'Accept: */*' -H 'Referer: https://blog.csdn.net/levon2018/article/details/80558108' -H 'Cookie: uuid_tt_dd=10_30744014340-1533110459408-320601; smidV2=2018082914272667751d1cac24793525732f74f62cbe9a0099f94a08e9b7de0; dc_session_id=10_1536825785870.531052; ARK_ID=JSa3a7b5f009df2bf82fa457adf0741aaaa3a7; Hm_lvt_6bcd52f51e9b3dce32bec4a3997715ac=1538100545,1538118577,1538119202,1538121038; dc_tos=pfrclv; Hm_lpvt_6bcd52f51e9b3dce32bec4a3997715ac=1538124692' -H 'Connection: keep-alive' --data-binary '[{"headers":{"component":"enterprise","datatype":"re","version":"v1"},"body":"{\"re\":\"uid=-&ref=&pid=blog&mod=popu_36&con=%2Chttps%3A%2F%2Fblog.csdn.net%2Fxixi880928%2Farticle%2Fdetails%2F78339157%2CBlogCommendFromBaidu_2&ck=-&curl=https%3A%2F%2Fblog.csdn.net%2Flevon2018%2Farticle%2Fdetails%2F80558108&session_id=10_1536825785870.531052&type=view\"}"},{"headers":{"component":"enterprise","datatype":"re","version":"v1"},"body":"{\"re\":\"uid=-&ref=&pid=blog&mod=popu_36&con=%2Chttps%3A%2F%2Fblog.csdn.net%2Fchaowanghn%2Farticle%2Fdetails%2F54601024%2CBlogCommendFromBaidu_3&ck=-&curl=https%3A%2F%2Fblog.csdn.net%2Flevon2018%2Farticle%2Fdetails%2F80558108&session_id=10_1536825785870.531052&type=view\"}"},{"headers":{"component":"enterprise","datatype":"re","version":"v1"},"body":"{\"re\":\"uid=-&ref=&pid=blog&mod=popu_36&con=%2Chttps%3A%2F%2Fblog.csdn.net%2Flanchunhui%2Farticle%2Fdetails%2F78877514%2CBlogCommendFromBaidu_4&ck=-&curl=https%3A%2F%2Fblog.csdn.net%2Flevon2018%2Farticle%2Fdetails%2F80558108&session_id=10_1536825785870.531052&type=view\"}"},{"headers":{"component":"enterprise","datatype":"re","version":"v1"},"body":"{\"re\":\"uid=-&ref=&pid=blog&mod=popu_36&con=%2Chttps%3A%2F%2Fblog.csdn.net%2Fsaw1990%2Farticle%2Fdetails%2F39287631%2CBlogCommendFromBaidu_5&ck=-&curl=https%3A%2F%2Fblog.csdn.net%2Flevon2018%2Farticle%2Fdetails%2F80558108&session_id=10_1536825785870.531052&type=view\"}"},{"headers":{"component":"enterprise","datatype":"re","version":"v1"},"body":"{\"re\":\"uid=-&ref=&pid=blog&mod=popu_36&con=%2Chttps%3A%2F%2Fblog.csdn.net%2Fu011044684%2Farticle%2Fdetails%2F45287575%2CBlogCommendFromBaidu_6&ck=-&curl=https%3A%2F%2Fblog.csdn.net%2Flevon2018%2Farticle%2Fdetails%2F80558108&session_id=10_1536825785870.531052&type=view\"}"},{"headers":{"component":"enterprise","datatype":"re","version":"v1"},"body":"{\"re\":\"uid=-&ref=&pid=blog&mod=popu_36&con=%2Chttps%3A%2F%2Fblog.csdn.net%2Fnimade511%2Farticle%2Fdetails%2F52540437%2CBlogCommendFromBaidu_7&ck=-&curl=https%3A%2F%2Fblog.csdn.net%2Flevon2018%2Farticle%2Fdetails%2F80558108&session_id=10_1536825785870.531052&type=view\"}"},{"headers":{"component":"enterprise","datatype":"re","version":"v1"},"body":"{\"re\":\"uid=-&ref=&pid=blog&mod=popu_36&con=%2Chttps%3A%2F%2Fblog.csdn.net%2Fpipisorry%2Farticle%2Fdetails%2F47948065%2CBlogCommendFromBaidu_8&ck=-&curl=https%3A%2F%2Fblog.csdn.net%2Flevon2018%2Farticle%2Fdetails%2F80558108&session_id=10_1536825785870.531052&type=view\"}"},{"headers":{"component":"enterprise","datatype":"re","version":"v1"},"body":"{\"re\":\"uid=-&ref=&pid=blog&mod=popu_36&con=%2Chttps%3A%2F%2Fblog.csdn.net%2Fyudiyanwang%2Farticle%2Fdetails%2F71843633%2CBlogCommendFromBaidu_9&ck=-&curl=https%3A%2F%2Fblog.csdn.net%2Flevon2018%2Farticle%2Fdetails%2F80558108&session_id=10_1536825785870.531052&type=view\"}"}]'` u, err := curl2info.ParseRawCURL(curl) if err != nil { panic(err) } resp, err := u.CreateWorkflow(nil).Execute() if err != nil { t.Error("TestExecute") } else { log.Println(resp.Content()) } } func TestExecutePlan(t *testing.T) { }