This commit is contained in:
aozhiwei 2024-06-05 17:03:52 +08:00
parent bf1664b48b
commit dcd28f7e45

View File

@ -80,27 +80,66 @@ func (this *httpCliMgr) SendGoStyleRequest(
cb) cb)
} }
func (this *httpCliMgr) SyncSendGoStyleRequest( func (this *httpCliMgr) SendGoStylePost(
url string, params map[string]string, url string, params map[string]string,
cb func(HttpCliResponse)) { contentType string, body string,
chDone := make(chan bool) cb func(HttpCliResponse)) HttpCliRequestHandle {
this.internalSendRequest( return this.internalSendPost(
GO_STYLE_REQUEST, GO_STYLE_REQUEST,
NORMAL_CHANNEL, NORMAL_CHANNEL,
url, url,
params, params,
nil, nil,
func(rsp HttpCliResponse) { contentType,
cb(rsp) body,
chDone <- true cb)
}) }
for {
select { func (this *httpCliMgr) SendGoStyleJsonRspPost(
case <-chDone: url string, params map[string]string,
close(chDone) jsonRspObj interface{},
return contentType string, body string,
} cb func(HttpCliResponse)) HttpCliRequestHandle {
} return this.internalSendPost(
GO_STYLE_REQUEST,
NORMAL_CHANNEL,
url,
params,
jsonRspObj,
contentType,
body,
cb)
}
func (this *httpCliMgr) SendJsStylePost(
url string, params map[string]string,
contentType string, body string,
cb func(HttpCliResponse)) HttpCliRequestHandle {
return this.internalSendPost(
JS_STYLE_REQUEST,
NORMAL_CHANNEL,
url,
params,
nil,
contentType,
body,
cb)
}
func (this *httpCliMgr) SendJsStyleJsonRspPost(
url string, params map[string]string,
jsonRspObj interface{},
contentType string, body string,
cb func(HttpCliResponse)) HttpCliRequestHandle {
return this.internalSendPost(
JS_STYLE_REQUEST,
NORMAL_CHANNEL,
url,
params,
jsonRspObj,
contentType,
body,
cb)
} }
func (this *httpCliMgr) SendJsStyleRequest( func (this *httpCliMgr) SendJsStyleRequest(
@ -176,6 +215,43 @@ func (this *httpCliMgr) internalSendRequest(
url string, params map[string]string, url string, params map[string]string,
jsonRspObj interface{}, jsonRspObj interface{},
cb func(HttpCliResponse)) HttpCliRequestHandle { cb func(HttpCliResponse)) HttpCliRequestHandle {
return this.internalSendGetOrPost(
true,
style,
channel,
url,
params,
jsonRspObj,
"",
"",
cb)
}
func (this *httpCliMgr) internalSendPost(
style int32, channel int32,
url string, params map[string]string,
jsonRspObj interface{},
contentType string, body string,
cb func(HttpCliResponse)) HttpCliRequestHandle {
return this.internalSendGetOrPost(
false,
style,
channel,
url,
params,
jsonRspObj,
contentType,
body,
cb)
}
func (this *httpCliMgr) internalSendGetOrPost(
isGet bool,
style int32, channel int32,
url string, params map[string]string,
jsonRspObj interface{},
contentType string, body string,
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")
} }
@ -185,9 +261,18 @@ func (this *httpCliMgr) internalSendRequest(
handle := &httpCliRequestHandleImpl{} handle := &httpCliRequestHandleImpl{}
doFunc := func() { doFunc := func() {
if atomic.CompareAndSwapInt32(&handle.state, 0, 1) { if atomic.CompareAndSwapInt32(&handle.state, 0, 1) {
data, err := q5.HttpGet(url, params) var data string
if cb == nil { var err error
return if isGet {
data, err = q5.HttpGet(url, params)
if cb == nil {
return
}
} else {
data, err = q5.HttpPost(url, params, contentType, body)
if cb == nil {
return
}
} }
rsp := new(httpCliResponse) rsp := new(httpCliResponse)
rsp.init(data, err) rsp.init(data, err)
@ -196,7 +281,7 @@ func (this *httpCliMgr) internalSendRequest(
if parseErr == nil { if parseErr == nil {
rsp.jsonParseOk = true rsp.jsonParseOk = true
} else { } else {
GetSysLog().Warning("f5.httpclimgr.internalSendRequest json error:%s url:%s params:%s", GetSysLog().Warning("f5.httpclimgr.internalSendGetOrPost json error:%s url:%s params:%s",
parseErr, parseErr,
url, url,
q5.EncodeJson(&params)) q5.EncodeJson(&params))