This commit is contained in:
aozhiwei 2024-03-21 12:07:27 +08:00
parent 803c5d7912
commit f60162262a

View File

@ -18,6 +18,14 @@ const (
QUICK_CHANNEL = 2
)
type HttpCliRequestHandle interface {
Cancel() bool
}
type httpCliRequestHandleImpl struct {
}
type HttpCliResponse interface {
GetErr() error
GetJsonData() map[string]interface{}
@ -35,6 +43,10 @@ type httpCliResponse struct {
type httpCliMgr struct {
}
func (this *httpCliRequestHandleImpl) Cancel() bool {
return true
}
func (this *httpCliMgr) init() {
_app.RegisterIMMsgHandle(
IM_HTTP_CLI_MGR_RESPONSE,
@ -50,8 +62,8 @@ func (this *httpCliMgr) unInit() {
func (this *httpCliMgr) SendGoStyleRequest(
url string, params map[string]string,
cb func(HttpCliResponse)) {
this.internalSendRequest(
cb func(HttpCliResponse)) HttpCliRequestHandle {
return this.internalSendRequest(
GO_STYLE_REQUEST,
NORMAL_CHANNEL,
url,
@ -83,8 +95,8 @@ func (this *httpCliMgr) SyncSendGoStyleRequest(
func (this *httpCliMgr) SendJsStyleRequest(
url string, params map[string]string,
cb func(HttpCliResponse)) {
this.internalSendRequest(
cb func(HttpCliResponse)) HttpCliRequestHandle {
return this.internalSendRequest(
JS_STYLE_REQUEST,
NORMAL_CHANNEL,
url,
@ -94,8 +106,8 @@ func (this *httpCliMgr) SendJsStyleRequest(
func (this *httpCliMgr) SendQuickChannelGoStyleRequest(
url string, params map[string]string,
cb func(HttpCliResponse)) {
this.internalSendRequest(
cb func(HttpCliResponse)) HttpCliRequestHandle {
return this.internalSendRequest(
GO_STYLE_REQUEST,
QUICK_CHANNEL,
url,
@ -105,8 +117,8 @@ func (this *httpCliMgr) SendQuickChannelGoStyleRequest(
func (this *httpCliMgr) SendQuickChannelJsStyleRequest(
url string, params map[string]string,
cb func(HttpCliResponse)) {
this.internalSendRequest(
cb func(HttpCliResponse)) HttpCliRequestHandle {
return this.internalSendRequest(
JS_STYLE_REQUEST,
QUICK_CHANNEL,
url,
@ -117,13 +129,14 @@ func (this *httpCliMgr) SendQuickChannelJsStyleRequest(
func (this *httpCliMgr) internalSendRequest(
style int32, channel int32,
url string, params map[string]string,
cb func(HttpCliResponse)) {
cb func(HttpCliResponse)) HttpCliRequestHandle {
if !(style == GO_STYLE_REQUEST || style == JS_STYLE_REQUEST) {
panic("httpCliMgr sytel error")
}
if !(channel == NORMAL_CHANNEL || channel == QUICK_CHANNEL) {
panic("httpCliMgr channel error")
}
handle := &httpCliRequestHandleImpl{}
doFunc := func() {
data, err := q5.HttpGet(url, params)
if cb == nil {
@ -141,6 +154,7 @@ func (this *httpCliMgr) internalSendRequest(
}
}
go doFunc()
return handle
}
func (this *httpCliResponse) init(data string, err error) {