| | |
| | | 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, |
| | | } |