增加连接超时参数控制
diff --git a/webservice.go b/webservice.go
index 6a9955e..d58b8f6 100644
--- a/webservice.go
+++ b/webservice.go
@@ -28,6 +28,8 @@
ErrBadCAPEM = errors.New("不正确的PEM文件")
)
+var connectionTimeout = time.Duration(500) * time.Millisecond
+
// WebSession web session object
type WebSession struct {
// AppId app id
@@ -130,8 +132,9 @@
}
fullURL = fullURL + "?" + vl.Encode()
return goreq.Request{Uri: fullURL,
- Method: "GET",
- Timeout: time.Duration(timeout) * time.Second}.Do()
+ Method: "GET",
+ Insecure: !w.sslVerify,
+ Timeout: time.Duration(timeout) * time.Second}.Do()
}
// GetTimestamp get time stamp format 20160103133455
@@ -202,6 +205,7 @@
Method: "POST",
ContentType: "application/json",
Body: data,
+ Insecure: !w.sslVerify,
Timeout: time.Duration(3) * time.Second}.Do()
if err != nil || r.StatusCode != 200 {
log.Errorf("Status=%v, err=%v", r, err)
@@ -365,6 +369,11 @@
return w.CallService2(path, params, timeout, signField...)
}
+// SetConnectionTimeout set global connection timeout
+func SetConnectionTimeout(ms int) {
+ connectionTimeout = time.Duration(ms) * time.Millisecond
+}
+
// CallService2 call epay service
func (w *WebSession) CallService2(path string, params map[string]interface{}, timeout int,
signField ...string) (response *ServiceResponse, err error) {
@@ -392,6 +401,7 @@
fullURL := w.BaseURL + path
log.Debugf("CallService: %v\n", fullURL)
+ goreq.SetConnectTimeout(connectionTimeout)
var r *goreq.Response
r, err = goreq.Request{
Uri: fullURL,