From b9d931da68f3929803c904e61a93628a56364e63 Mon Sep 17 00:00:00 2001 From: eson Date: Wed, 25 Nov 2020 17:43:33 +0800 Subject: [PATCH] feat(context): add Unmarshal json --- callback.go | 23 +++++++++++++++++++++++ client.go | 15 --------------- 2 files changed, 23 insertions(+), 15 deletions(-) create mode 100644 callback.go diff --git a/callback.go b/callback.go new file mode 100644 index 0000000..33a98c7 --- /dev/null +++ b/callback.go @@ -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) +} diff --git a/client.go b/client.go index cce9fe0..9cc6edf 100644 --- a/client.go +++ b/client.go @@ -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