From 7644cbe1a254fbd21759b171503593cff9b02a78 Mon Sep 17 00:00:00 2001 From: eson <474420502@qq.com> Date: Tue, 27 Nov 2018 03:48:25 +0800 Subject: [PATCH] TODO Proxy DeepCopy Test --- execute_test.go | 47 ++++++++++++++++++++++++++++++++++++++++------- structure.go | 27 ++++++++++++++++++++++++--- 2 files changed, 64 insertions(+), 10 deletions(-) diff --git a/execute_test.go b/execute_test.go index 33457e1..afe3d75 100644 --- a/execute_test.go +++ b/execute_test.go @@ -11,24 +11,57 @@ import ( ) type Person struct { - Tasks []Task + Tasks *CircularLinked Conf *Config } type Task struct { - Curl *curl2info.CURL - Plan *ExecutePlan + Curl *curl2info.CURL + Plan *CircularLinked + Proxies *CircularLinked } func NewPerson(conf string, curlinfo string) *Person { - return nil + 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(curlinfo string, Plan *ExecutePlan) *Task { +func NewTask(Curl *curl2info.CURL, Plans ...IExecute) *Task { task := &Task{} // task.Conf = NewConfig(conf) - task.Curl = curl2info.NewCURL(curlinfo) - task.Plan = Plan + task.Curl = Curl + task.Plan = NewCircularLinked(Plans) + task.Proxies = NewCircularLinked() return task } diff --git a/structure.go b/structure.go index 415378a..35d8698 100644 --- a/structure.go +++ b/structure.go @@ -1,6 +1,8 @@ package imitate import ( + "bytes" + "encoding/gob" "log" "strings" @@ -41,13 +43,19 @@ func (list *CircularLinked) Cursor() *Node { // CursorNext get next Cursor func (list *CircularLinked) CursorNext() *Node { - list.cursor = list.Cursor().next + if list.cursor == nil { + list.cursor = list.head + } + list.cursor = list.cursor.next return list.cursor } // CursorPrev get prev Cursor func (list *CircularLinked) CursorPrev() *Node { - list.cursor = list.Cursor().prev + if list.cursor == nil { + list.cursor = list.head + } + list.cursor = list.cursor.prev return list.cursor } @@ -195,7 +203,20 @@ func (list *CircularLinked) Size() uint64 { func (list *CircularLinked) Clone() *CircularLinked { cl := NewCircularLinked() for i := uint64(0); i < list.size; i++ { - cl.Append(list.cursor.value) + var buf bytes.Buffer // Stand-in for a network connection + enc := gob.NewEncoder(&buf) // Will write to network. + dec := gob.NewDecoder(&buf) // Will read from network. + // Encode (send) the value. + err := enc.Encode(list.cursor.value) + if err != nil { + log.Fatal("encode error:", err) + } + var clonevalue interface{} + err = dec.Decode(clonevalue) + if err != nil { + panic(err) + } + cl.Append(clonevalue) } return cl }