TODO Proxy DeepCopy Test
This commit is contained in:
parent
121cf7c67d
commit
7644cbe1a2
|
@ -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
|
||||
}
|
||||
|
|
27
structure.go
27
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user