liuxiaolong
2020-05-28 0d251e8d1a5ba99f1186daa20ca88f90d1bf6c29
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,
   }