From 0d251e8d1a5ba99f1186daa20ca88f90d1bf6c29 Mon Sep 17 00:00:00 2001
From: liuxiaolong <liuxiaolong@aiotlink.com>
Date: 星期四, 28 五月 2020 18:46:20 +0800
Subject: [PATCH] add log

---
 EsClient.go |   69 ++++++++++++++++++++++++++++++++++
 1 files changed, 68 insertions(+), 1 deletions(-)

diff --git a/EsClient.go b/EsClient.go
index 0d608a9..39754cf 100644
--- a/EsClient.go
+++ b/EsClient.go
@@ -542,9 +542,76 @@
 	return data, nil
 }
 
+func SourceCreated(buf []byte) (result bool, err error) {
+	var info interface{}
+	json.Unmarshal(buf, &info)
+	out, ok := info.(map[string]interface{})
+	if !ok {
+		return false, errors.New("http response interface can not change map[string]interface{}")
+	}
+
+	middle, ok := out["result"].(string)
+	if !ok {
+		return false, errors.New("first total change error!")
+	}
+	if middle == "created" || middle == "updated" {
+		result = true
+	}
+	return result, nil
+}
+
+func SourceDeleted(buf []byte) (total int, err error) {
+	var info interface{}
+	json.Unmarshal(buf, &info)
+	out, ok := info.(map[string]interface{})
+	if !ok {
+		return -1, errors.New("http response interface can not change map[string]interface{}")
+	}
+
+	middle, ok := out["deleted"].(float64)
+	if !ok {
+		return -1, errors.New("first total change error!")
+	}
+	total = int(middle)
+	return total, nil
+}
+
+func SourceUpdated(buf []byte) (total int, err error) {
+	var info interface{}
+	json.Unmarshal(buf, &info)
+	out, ok := info.(map[string]interface{})
+	if !ok {
+		return -1, errors.New("http response interface can not change map[string]interface{}")
+	}
+
+	middle, ok := out["updated"].(float64)
+	if !ok {
+		return -1, errors.New("first total change error!")
+	}
+	total = int(middle)
+	return total, nil
+}
+
+func SourceTotal(buf []byte) (total int, err error) {
+	var info interface{}
+	json.Unmarshal(buf, &info)
+	out, ok := info.(map[string]interface{})
+	if !ok {
+		return -1, errors.New("http response interface can not change map[string]interface{}")
+	}
+
+	middle, ok := out["hits"].(map[string]interface{})
+	if !ok {
+		return -1, errors.New("first total change error!")
+	}
+	tmp := middle["total"].(float64)
+	total = int(tmp)
+	return total, nil
+}
+
 func EsReq(method string, url string, parama []byte) (buf []byte, err error) {
 	//defer elapsed("page")()
-	timeout := time.Duration(10 * time.Second)
+	timeout := time.Duration(100 * time.Second)
 	client := http.Client{
 		Timeout: timeout,
 	}

--
Gitblit v1.8.0