feat(context): add Unmarshal json
This commit is contained in:
parent
2623502cc8
commit
b9d931da68
23
callback.go
Normal file
23
callback.go
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
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)
|
||||||
|
}
|
15
client.go
15
client.go
|
@ -21,21 +21,6 @@ func init() {
|
||||||
log.SetFlags(log.Llongfile | log.LstdFlags)
|
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 客户端
|
// Client 客户端
|
||||||
type Client struct {
|
type Client struct {
|
||||||
chromeProxyAddr string
|
chromeProxyAddr string
|
||||||
|
|
Loading…
Reference in New Issue
Block a user