diff --git a/httpclimgr.go b/httpclimgr.go index b33377e..d7ca04b 100644 --- a/httpclimgr.go +++ b/httpclimgr.go @@ -80,27 +80,66 @@ func (this *httpCliMgr) SendGoStyleRequest( cb) } -func (this *httpCliMgr) SyncSendGoStyleRequest( +func (this *httpCliMgr) SendGoStylePost( url string, params map[string]string, - cb func(HttpCliResponse)) { - chDone := make(chan bool) - this.internalSendRequest( + contentType string, body string, + cb func(HttpCliResponse)) HttpCliRequestHandle { + return this.internalSendPost( GO_STYLE_REQUEST, NORMAL_CHANNEL, url, params, nil, - func(rsp HttpCliResponse) { - cb(rsp) - chDone <- true - }) - for { - select { - case <-chDone: - close(chDone) - return - } - } + contentType, + body, + cb) +} + +func (this *httpCliMgr) SendGoStyleJsonRspPost( + url string, params map[string]string, + jsonRspObj interface{}, + 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( @@ -176,6 +215,43 @@ func (this *httpCliMgr) internalSendRequest( url string, params map[string]string, jsonRspObj interface{}, 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) { panic("httpCliMgr sytel error") } @@ -185,9 +261,18 @@ func (this *httpCliMgr) internalSendRequest( handle := &httpCliRequestHandleImpl{} doFunc := func() { if atomic.CompareAndSwapInt32(&handle.state, 0, 1) { - data, err := q5.HttpGet(url, params) - if cb == nil { - return + var data string + var err error + 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.init(data, err) @@ -196,7 +281,7 @@ func (this *httpCliMgr) internalSendRequest( if parseErr == nil { rsp.jsonParseOk = true } 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, url, q5.EncodeJson(¶ms))