]> 127.0.0.1 Git - part/.git/commitdiff
92
authorqydysky <qydysky@foxmail.com>
Tue, 17 Nov 2020 21:33:40 +0000 (05:33 +0800)
committerqydysky <qydysky@foxmail.com>
Tue, 17 Nov 2020 21:33:40 +0000 (05:33 +0800)
README.md
Reqf.go
get/Get.go
msgq/Msgq.go [new file with mode: 0644]
msgq/Msgq_test.go [new file with mode: 0644]

index 061ceb9a2bec46801de515bad34b33d2b1f11ed1..78e21dd9c4b4ed2be163fd14e94ea97a752c4820 100644 (file)
--- a/README.md
+++ b/README.md
@@ -4,4 +4,12 @@
 #### 介绍\r
 自己编写/收集的一些go组件,增加复用\r
 \r
-使用代理 `export GOPROXY="https://goproxy.io"`\r
+buf map变量的save,load,get,set\r
+\r
+get 爬虫\r
+\r
+session 会话(超时)验证\r
+\r
+msgq 消息队列\r
+\r
+...
\ No newline at end of file
diff --git a/Reqf.go b/Reqf.go
index d9f3fe00357293221926d0320776445bdd623a40..b0b9dfb38ef4a4b871b91660bf4cf09f3d760d58 100644 (file)
--- 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")
index c552d1bc5a6a7a9e632124fc64e6f13535503e1e..6e3e16303c547a36e6f74098ec026b46aa7505d6 100644 (file)
@@ -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 (file)
index 0000000..bfdddc1
--- /dev/null
@@ -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 (file)
index 0000000..7c7a4d9
--- /dev/null
@@ -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`)
+}