ref: 23690d53dd05b1a2051fcb8745a1c1a8d45165c1
server/rest/rest-position.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 41 42 43 44 |
package rest import ( "fmt" "github.com/gin-gonic/gin" "net/http" "time" "yats-server/config" "yats-server/db" "yats-server/model" ) // WritePosition godoc // @Param X-SSL-Client-CN header string true "clientCN" // @Summary write position to db // @Schemes // @Description store position // @Tags Events // @Accept json // @Param position body model.PositionModel true "Position body data" // @Produce json // @Success 202 {string} WriteEvent // @Router /position [post] func WritePosition(cfg config.Configuration) gin.HandlerFunc { return func(c *gin.Context) { var position model.PositionModel if err := c.BindJSON(&position); err != nil { c.IndentedJSON(http.StatusAccepted, gin.H{"ret": "-1"}) return } clientCN := GetClientCN(c, cfg) fmt.Printf("%s / %s ", clientCN, position.Name) if position.Ptime == 0 { db.SavePosition(clientCN, position.Lat, position.Lon, position.Name) } else { unixTimeUTC := time.Unix(position.Ptime, 0) db.SavePositionAt(clientCN, position.Lat, position.Lon, unixTimeUTC, position.Name) } c.IndentedJSON(http.StatusAccepted, gin.H{"ret": "OK"}) } } |