From daf7c4ec7270af5fc0b87eeaa3da1909d299be70 Mon Sep 17 00:00:00 2001
From: liuxiaolong <liuxiaolong@qq.com>
Date: 星期四, 09 五月 2019 20:52:49 +0800
Subject: [PATCH] common get and post

---
 httpClient.go |   29 +++++++++++++++++++----------
 1 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/httpClient.go b/httpClient.go
index 3373e50..de800f7 100644
--- a/httpClient.go
+++ b/httpClient.go
@@ -16,6 +16,23 @@
 	BASIC_URL = "http://192.168.1.182:8000"
 )
 
+func DoRequest(request *http.Request, contentType string) ([]byte, error) {
+	var body []byte
+	request.Header.Add("Content-Type", contentType)
+	timeout := time.Duration(5 * time.Second) //瓒呮椂鏃堕棿50ms
+	client := &http.Client{Timeout: timeout}
+	resp, err := client.Do(request)
+	if err != nil {
+		return body, err
+	}
+	defer resp.Body.Close()
+	body, err = ioutil.ReadAll(resp.Body)
+	if err != nil {
+		return body, err
+	}
+	return body, nil
+}
+
 //閫氳繃cameraId鑾峰彇鎽勫儚鏈轰俊鎭�
 func (api DbApi) GetCameraById(cameraId string) (result Camera, err error) {
 	url := BASIC_URL + "/data/api-v/camera/show/" + cameraId
@@ -23,16 +40,8 @@
 	if err != nil {
 		return result, err
 	}
-	request.Header.Add("Content-Type", "application/json")
-	timeout := time.Duration(5 * time.Second) //瓒呮椂鏃堕棿50ms
-	client := &http.Client{Timeout: timeout}
-	resp, err := client.Do(request)
-	if err != nil {
-		return result, err
-	}
-	defer resp.Body.Close()
-
-	body, err := ioutil.ReadAll(resp.Body)
+	
+	body, err := DoRequest(request, "application/json")
 	if err != nil {
 		return result, err
 	}

--
Gitblit v1.8.0