From ef56d5480392d75a15c8c16a24a1ce8c54fe435a Mon Sep 17 00:00:00 2001 From: qydysky Date: Wed, 18 Nov 2020 05:33:40 +0800 Subject: [PATCH] 92 --- README.md | 10 +++++++++- Reqf.go | 2 ++ get/Get.go | 3 ++- msgq/Msgq.go | 38 ++++++++++++++++++++++++++++++++++++++ msgq/Msgq_test.go | 27 +++++++++++++++++++++++++++ 5 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 msgq/Msgq.go create mode 100644 msgq/Msgq_test.go diff --git a/README.md b/README.md index 061ceb9..78e21dd 100644 --- a/README.md +++ b/README.md @@ -4,4 +4,12 @@ #### 介绍 自己编写/收集的一些go组件,增加复用 -使用代理 `export GOPROXY="https://goproxy.io"` +buf map变量的save,load,get,set + +get 爬虫 + +session 会话(超时)验证 + +msgq 消息队列 + +... \ No newline at end of file diff --git a/Reqf.go b/Reqf.go index d9f3fe0..b0b9dfb 100644 --- a/Reqf.go +++ b/Reqf.go @@ -11,6 +11,7 @@ import ( "errors" "io/ioutil" "net/url" + "log" compress "github.com/qydysky/part/compress" // "encoding/binary" ) @@ -142,6 +143,7 @@ func (this *req) Reqf_1(val Rval) (error) { if err != nil { return err } + log.Println(Map_2_Cookies_String(Cookies_List_2_Map(resp.Cookies()))) var saveToFile func(io.Reader,string)error = func (Body io.Reader,filepath string) error { out, err := os.Create(filepath + ".dtmp") diff --git a/get/Get.go b/get/Get.go index c552d1b..6e3e163 100644 --- a/get/Get.go +++ b/get/Get.go @@ -1,6 +1,7 @@ package part import ( + // "log" "strings" "errors" "net/http" @@ -24,7 +25,7 @@ func Get(r p.Rval) (o *get){ o.Err = R.Reqf(r) (*o).body = R.Respon (*o).Response = R.Response - + return } diff --git a/msgq/Msgq.go b/msgq/Msgq.go new file mode 100644 index 0000000..bfdddc1 --- /dev/null +++ b/msgq/Msgq.go @@ -0,0 +1,38 @@ +package part + +type msgq struct { + o chan interface{} + men chan bool +} + +type cancle int + +func New() (*msgq) { + l := new(msgq) + (*l).o = make(chan interface{}) + (*l).men = make(chan bool) + return l +} + +func (m *msgq) Push(msg interface{}) { + if len(m.men) == 0 {return} + for <- m.men { + m.o <- msg + } + for len(m.o) != 0 { + <- m.o + } +} + +func (m *msgq) Pull(cancleId int) (o interface{}) { + m.men <- true + for { + o = <- m.o + if v,ok := o.(cancle);!ok || int(v) != cancleId {break} + } + return +} + +func (m *msgq) Cancle(cancleId int) { + m.Push(cancle(cancleId)) +} \ No newline at end of file diff --git a/msgq/Msgq_test.go b/msgq/Msgq_test.go new file mode 100644 index 0000000..7c7a4d9 --- /dev/null +++ b/msgq/Msgq_test.go @@ -0,0 +1,27 @@ +package part + +import ( + "testing" + p "github.com/qydysky/part" +) + +func Test_msgq(t *testing.T) { + mq := New() + go func(){ + for mq.Pull(0).(string) == `mmm` {;} + t.Error(`0`) + }() + go func(){ + for { + o := mq.Pull(1) + if o.(string) == `mmm` || o == nil {continue} + break + } + t.Error(`1`) + }() + p.Sys().Timeoutf(1) + mq.Push(`mmm`) + p.Sys().Timeoutf(1) + mq.Cancle(1) + mq.Push(`mmm`) +} -- 2.39.2