diff --git a/httpclimgr.go b/httpclimgr.go index b0f99c0..94a8292 100644 --- a/httpclimgr.go +++ b/httpclimgr.go @@ -2,6 +2,7 @@ package f5 import ( "q5" + "encoding/json" "sync/atomic" ) @@ -33,6 +34,7 @@ type HttpCliResponse interface { GetJsonData() map[string]interface{} GetRawData() string IsTimeOut() bool + JsonParseOk() bool } type httpCliResponse struct { @@ -40,6 +42,7 @@ type httpCliResponse struct { data map[string]interface{} rawData string isTimeOut bool + jsonParseOk bool } type httpCliMgr struct { @@ -73,6 +76,7 @@ func (this *httpCliMgr) SendGoStyleRequest( NORMAL_CHANNEL, url, params, + nil, cb) } @@ -85,6 +89,7 @@ func (this *httpCliMgr) SyncSendGoStyleRequest( NORMAL_CHANNEL, url, params, + nil, func(rsp HttpCliResponse) { cb(rsp) chDone <- true @@ -106,6 +111,23 @@ func (this *httpCliMgr) SendJsStyleRequest( NORMAL_CHANNEL, url, params, + nil, + cb) +} + +func (this *httpCliMgr) SendJsStyleJsonRspRequest( + url string, params map[string]string, + jsonRspObj interface{}, + cb func(HttpCliResponse)) HttpCliRequestHandle { + if jsonRspObj == nil { + panic("SendJsStyleJsonRspRequest error jsonRspobj is nil") + } + return this.internalSendRequest( + JS_STYLE_REQUEST, + NORMAL_CHANNEL, + url, + params, + jsonRspObj, cb) } @@ -117,6 +139,7 @@ func (this *httpCliMgr) SendQuickChannelGoStyleRequest( QUICK_CHANNEL, url, params, + nil, cb) } @@ -128,12 +151,30 @@ func (this *httpCliMgr) SendQuickChannelJsStyleRequest( QUICK_CHANNEL, url, params, + nil, + cb) +} + +func (this *httpCliMgr) SendQuickChannelJsStyleJsonRspRequest( + url string, params map[string]string, + jsonRspObj interface{}, + cb func(HttpCliResponse)) HttpCliRequestHandle { + if jsonRspObj == nil { + panic("SendJsStyleJsonRspRequest error jsonRspobj is nil") + } + return this.internalSendRequest( + JS_STYLE_REQUEST, + QUICK_CHANNEL, + url, + params, + jsonRspObj, cb) } func (this *httpCliMgr) internalSendRequest( style int32, channel int32, url string, params map[string]string, + jsonRspObj interface{}, cb func(HttpCliResponse)) HttpCliRequestHandle { if !(style == GO_STYLE_REQUEST || style == JS_STYLE_REQUEST) { panic("httpCliMgr sytel error") @@ -150,6 +191,11 @@ func (this *httpCliMgr) internalSendRequest( } rsp := new(httpCliResponse) rsp.init(data, err) + if rsp.GetErr() == nil && jsonRspObj != nil { + if json.Unmarshal([]byte(rsp.GetRawData()), jsonRspObj) == nil { + rsp.jsonParseOk = true + } + } if style == GO_STYLE_REQUEST { cb(rsp) } else { @@ -184,3 +230,7 @@ func (this *httpCliResponse) GetRawData() string { func (this *httpCliResponse) IsTimeOut() bool { return this.isTimeOut } + +func (this *httpCliResponse) JsonParseOk() bool { + return this.jsonParseOk +}