feat(context): add Unmarshal json

This commit is contained in:
eson 2020-11-25 17:43:33 +08:00
parent 2623502cc8
commit b9d931da68
2 changed files with 23 additions and 15 deletions

23
callback.go Normal file
View 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)
}

View File

@ -21,21 +21,6 @@ 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