#### 介绍\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
"errors"
"io/ioutil"
"net/url"
+ "log"
compress "github.com/qydysky/part/compress"
// "encoding/binary"
)
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")
package part
import (
+ // "log"
"strings"
"errors"
"net/http"
o.Err = R.Reqf(r)
(*o).body = R.Respon
(*o).Response = R.Response
-
+
return
}
--- /dev/null
+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
--- /dev/null
+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`)
+}