Compare commits
No commits in common. "v0.2.3" and "master" have entirely different histories.
23
callback.go
23
callback.go
|
@ -1,23 +0,0 @@
|
|||
package cwclient
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
// Callback 发送代理连接获取内容后的回调函数
|
||||
type Callback struct {
|
||||
label string
|
||||
hash string
|
||||
Do func(cxt *CallbackContext)
|
||||
}
|
||||
|
||||
// CallbackContext Callback上下文
|
||||
type CallbackContext struct {
|
||||
TaskID string
|
||||
Content string
|
||||
Error error
|
||||
Carry interface{} // 传递的参数.
|
||||
}
|
||||
|
||||
// ContentJSON 返回 json反序列化的对象
|
||||
func (cxt *CallbackContext) ContentJSON(obj interface{}) error {
|
||||
return json.Unmarshal([]byte(cxt.Content), obj)
|
||||
}
|
20
client.go
20
client.go
|
@ -21,6 +21,21 @@ func init() {
|
|||
log.SetFlags(log.Llongfile | log.LstdFlags)
|
||||
}
|
||||
|
||||
// CallbackContext Callback上下文
|
||||
type CallbackContext struct {
|
||||
TaskID string
|
||||
Content string
|
||||
Error error
|
||||
Carry interface{} // 传递的参数.
|
||||
}
|
||||
|
||||
// Callback 发送代理连接获取内容后的回调函数
|
||||
type Callback struct {
|
||||
label string
|
||||
hash string
|
||||
Do func(cxt *CallbackContext)
|
||||
}
|
||||
|
||||
// Client 客户端
|
||||
type Client struct {
|
||||
chromeProxyAddr string
|
||||
|
@ -168,10 +183,7 @@ func (cli *Client) Connect() {
|
|||
}
|
||||
cli.port = fmt.Sprintf("%d", listener.Addr().(*net.TCPAddr).Port)
|
||||
|
||||
router := gin.New()
|
||||
router.Use(gin.Recovery())
|
||||
gin.SetMode(gin.ReleaseMode)
|
||||
|
||||
router := gin.Default()
|
||||
router.POST("/:label", func(c *gin.Context) {
|
||||
label := c.Param("label")
|
||||
if f, ok := cli.register.Load(label); ok {
|
||||
|
|
|
@ -5,30 +5,8 @@ import (
|
|||
"log"
|
||||
"net/http"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestSelectChan(t *testing.T) {
|
||||
var a chan string = make(chan string)
|
||||
var b chan string = make(chan string)
|
||||
|
||||
go func() {
|
||||
time.Sleep(time.Second * 2)
|
||||
a <- "1"
|
||||
time.Sleep(time.Second * 2)
|
||||
b <- "2"
|
||||
}()
|
||||
|
||||
select {
|
||||
case s := <-a:
|
||||
log.Println("a", s)
|
||||
case s := <-b:
|
||||
log.Println("b", s)
|
||||
case <-time.After(time.Second * 5):
|
||||
log.Println("timeout 5s")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPort(t *testing.T) {
|
||||
cli := New("http://localhost:7123")
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user