This commit is contained in:
aozhiwei 2024-03-21 15:44:07 +08:00
parent fbaad6f524
commit a149beea06

View File

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