sunty
2019-09-29 b7a57cd830201952d76b5df4c7e10097317d4f10
EsClient.go
@@ -7,7 +7,8 @@
    "fmt"
    "io/ioutil"
    "net/http"
    "time"
   "strconv"
   "time"
    "basic.com/pubsub/protomsg.git"
)
@@ -109,9 +110,11 @@
        tmpinfo.BeautyLevel,ok = source["beautyLevel"].(string)
        Isnil("beautyLevel",ok)
        if source["picSmUrl"] != nil {
            //fmt.Println(source["picSmUrl"])
            for _,v := range source["picSmUrl"].([]interface{}) {
                tmpinfo.PicSmUrl = append(tmpinfo.PicSmUrl, v.(string))
            }
            fmt.Println(tmpinfo.PicSmUrl)
        }
        tmpinfo.VideoUrl,ok = source["videoUrl"].(string)
        Isnil("videoUrl",ok)
@@ -123,21 +126,33 @@
        Isnil("analyServerIp",ok)
        tmpinfo.ClusterId,ok = source["clusterId"].(string)
        Isnil("clusterId",ok)
        tmpinfo.IsAlarm,ok = source["isAlarm"].(string)
        isAlarm,ok := source["isAlarm"].(float64)
        fmt.Println(ok)
      if ok {
         tmpinfo.IsAlarm= strconv.FormatFloat(isAlarm, 'E', -1, 64)//float64
      }
        Isnil("isAlarm",ok)
        tmpinfo.IsAckAlarm,ok = source["isAckAlarm"].(string)
        Isnil("isAckAlarm",ok)
      isAckAlarm,ok := source["isAckAlarm"].(float64)
      fmt.Println(ok)
      if ok {
         tmpinfo.IsAckAlarm= strconv.FormatFloat(isAckAlarm, 'E', -1, 64)//float64
      }
      Isnil("isAckAlarm",ok)
        isCollect,ok  :=   source["isCollect"].(float64)
        if ok {
            tmpinfo.IsDelete= int32(isCollect)
        }
        Isnil("isDelete", ok)
        Isnil("isCollect", ok)
        isDelete,ok  :=   source["isDelete"].(float64)
        if ok {
            tmpinfo.IsDelete= int32(isDelete)
        }
        Isnil("isDelete", ok)
        if source["alarmRules"] != nil {
            fmt.Println(source["alarmRules"])
            for _,v := range source["alarmRules"].([]interface{}) {
@@ -195,12 +210,12 @@
                tmpinfo.BaseInfo = append(tmpinfo.BaseInfo, &bi)
            }
        }
        //根据 tableid 获取 tablename
        //name, _:= Dbtablename(tmpinfo.TableId)
        //tmpinfo.TableName= name
        fmt.Println(tmpinfos)
        tmpinfos = append(tmpinfos, tmpinfo)
    }
@@ -358,8 +373,47 @@
    return sources,nil
}
func Sourcelistforscroll(buf []byte)(datasource map[string]interface{}, err error){
   var data = make(map[string]interface{})
   var info interface{}
   json.Unmarshal(buf, &info)
   out, ok := info.(map[string]interface{})
   if !ok {
      return nil, errors.New("http response interface can not change map[string]interface{}")
   }
   scroll_id, ok := out["_scroll_id"].(string)
   if !ok {
      return nil, errors.New("first hits change error!")
   }
   //fmt.Println("middle: ",scroll_id)
   middle, ok := out["hits"].(map[string]interface{})
   //fmt.Println("middle: ",out)
   if !ok {
      return nil, errors.New("first hits change error!")
   }
   var sources  = make([]map[string]interface{},0)
   for _, in := range middle["hits"].([]interface{}){
      tmpbuf, ok := in.(map[string]interface{})
      if !ok {
         fmt.Println("change to source error!")
         continue
      }
      source, ok := tmpbuf["_source"].(map[string]interface{})
      if !ok {
         fmt.Println("change _source error!")
         continue
      }
      sources  = append(sources, source )
   }
   data["sourcelist"] = sources
   data["scroll_id"] = scroll_id
   return data,nil
}
func EsReq(method string, url string, parama []byte) (buf []byte, err error) {
    defer elapsed("page")()
    //defer elapsed("page")()
    timeout := time.Duration(10 * time.Second) 
    client := http.Client{
        Timeout: timeout,