增加连接超时参数控制
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,
diff --git a/webservice_test.go b/webservice_test.go
index 00393a2..8c0294d 100644
--- a/webservice_test.go
+++ b/webservice_test.go
@@ -37,7 +37,7 @@
)
func TestUseHTTP(t *testing.T) {
- uri := "http://vb-docker:8443/epayapi/services"
+ uri := "http://ykt.supwisdom.com/epayapi/services"
session := NewSession(appID, appSecret, termID, uri, 3, true)
err := session.Auth()
if err != nil {
@@ -46,7 +46,7 @@
}
func TestUseHTTPS(t *testing.T) {
- uri := "https://vb-docker:8443/epayapi/services"
+ uri := "https://ykt.supwisdom.com/epayapi/services"
session, err := NewSessionWithCA(appID, appSecret, termID, uri, 3, []byte(caPEM))
if err != nil {
t.Error("New Session , ", err)
@@ -60,7 +60,7 @@
}
func TestUseSecureHTTPS(t *testing.T) {
- uri := "https://www.baidu.com"
+ uri := "https://ykt.supwisdom.com/epayapi/services"
session := NewSession(appID, appSecret, termID, uri, 3, true)
err := session.Auth()
if err != nil {