ref: 0102aa21efe7d4d94a56fc48566c89232fb68064
client/position-client-rest.go
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
package main import ( "errors" "fmt" "strconv" ) func (c *YatsClient) PositionList(source string, from int64, to int64) string { if from == 0 { panic("From is empty") } var body string if to == 0 { body = "{\"source\": \"" + source + "\", \"from\":" + strconv.FormatInt(from, 10) + " }" } else { body = "{\"source\": \"" + source + "\", \"from\":" + strconv.FormatInt(from, 10) + ",\"to\":" + strconv.FormatInt(to, 10) + " }" } //fmt.Printf("request: [%s]\n", body) return c.ApiPost(c.config.Endpoint+"/position/search", body) } func (c *YatsClient) PositionSave(positionName string, lat float64, lon float64, ptime int64) (string, error) { if positionName == "" { //fmt.Println("Metric Name is empty") return "", errors.New("position name is empty") } if lat == 0 && lon == 0 { //fmt.Println("Metric Name is empty") return "", errors.New("Lat/Lon was 0,0") } var body string if ptime == 0 { body = "{ \"name\":\"" + positionName + "\", \"lat\": " + strconv.FormatFloat(lat, 'f', -1, 64) + ", \"lon\":" + strconv.FormatFloat(lon, 'f', -1, 64) + " }" } else { body = "{ \"name\":\"" + positionName + ", \"lat\": " + strconv.FormatFloat(lat, 'f', -1, 64) + ", \"lon\":" + strconv.FormatFloat(lon, 'f', -1, 64) + ", \"ptime\":\"" + strconv.FormatInt(ptime, 10) + "\" }" } fmt.Printf("payload: [%s]\n", body) return c.ApiPost(c.config.Endpoint+"/position", body), nil } |