sunty
2019-07-12 d42b09cda8b2bc58c43c200f3aabdb0b2a7e9211
extend/esutil/EsClient.go
@@ -9,7 +9,6 @@
   "log"
   "mime/multipart"
   "net/http"
   "strconv"
   "strings"
   "time"
@@ -46,11 +45,11 @@
      for _, value := range dat["hits"].([]interface{}) {
         source := value.(map[string]interface{})["_source"].(map[string]interface{})
         source["id"] = value.(map[string]interface{})["_id"]
         sdkType := source["sdkType"]
         /*sdkType := source["sdkType"]
         if sdkType != nil {
            sdk, _ := strconv.Atoi(sdkType.(string))
            source["sdkType"] = sdkTypeToValue(sdk)
         }
         }*/
         sources = append(sources, source)
      }
      data["datalist"] = sources
@@ -62,10 +61,10 @@
}
//sdk类型
func sdkTypeToValue(i int) string {
/*func sdkTypeToValue(i int) string {
   value := []string{"人脸", "车辆", "人体", "入侵", "拥挤", "靠右行", "人员异常", "个体静止"}
   return value[i-1]
}
}*/
func PutEsDataReq(url string, parama string) (map[string]interface{}, error) {
   //fmt.Println("es 查询请求路径" + url) //  配置信息 获取
@@ -99,7 +98,7 @@
   return dat, nil
}
func PostFormData(uri string, filename, paramName string, file multipart.File) (maps map[string]interface{}, err0 error) {
func PostFormData(uri string, filename, paramName string, fileBytes []byte) (maps map[string]interface{}, err0 error) {
   body := &bytes.Buffer{}
   writer := multipart.NewWriter(body)
   _, err := writer.CreateFormFile(paramName, filename)
@@ -107,11 +106,11 @@
      return nil, err
   }
   boundary := writer.Boundary()
   //close_string := fmt.Sprintf("\r\n--%s--\r\n", boundary)
   close_buf := bytes.NewBufferString(fmt.Sprintf("\r\n--%s--\r\n", boundary))
   fmt.Println("PostFormData.fileLen:",len(fileBytes))
   file := bytes.NewBuffer(fileBytes)
   request_reader := io.MultiReader(body, file, close_buf)
   //_, err = io.Copy(part, file)
   //writer.WriteField(key, val)
   request, err := http.NewRequest("POST", uri, request_reader)
   request.Header.Add("Content-Type", writer.FormDataContentType())
   timeout := time.Duration(5 * time.Second) //超时时间50ms