| 1 |
package server |
| 2 |
|
| 3 |
import ( |
| 4 |
"github.com/gin-gonic/gin" |
| 5 |
"github.com/henrybear327/go-proton-api" |
| 6 |
"net/http" |
| 7 |
) |
| 8 |
|
| 9 |
func (s *Server) handlePostDataStats() gin.HandlerFunc { |
| 10 |
return func(c *gin.Context) { |
| 11 |
var req proton.SendStatsReq |
| 12 |
|
| 13 |
if err := c.BindJSON(&req); err != nil { |
| 14 |
c.AbortWithStatus(http.StatusBadRequest) |
| 15 |
return |
| 16 |
} |
| 17 |
|
| 18 |
if !validateSendStatReq(&req) { |
| 19 |
c.AbortWithStatus(http.StatusBadRequest) |
| 20 |
return |
| 21 |
} |
| 22 |
|
| 23 |
c.JSON(http.StatusOK, gin.H{ |
| 24 |
"Code": proton.SuccessCode, |
| 25 |
}) |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
func (s *Server) handlePostDataStatsMultiple() gin.HandlerFunc { |
| 30 |
return func(c *gin.Context) { |
| 31 |
var req proton.SendStatsMultiReq |
| 32 |
|
| 33 |
if err := c.BindJSON(&req); err != nil { |
| 34 |
c.AbortWithStatus(http.StatusBadRequest) |
| 35 |
return |
| 36 |
} |
| 37 |
|
| 38 |
for _, event := range req.EventInfo { |
| 39 |
if !validateSendStatReq(&event) { |
| 40 |
c.AbortWithStatus(http.StatusBadRequest) |
| 41 |
return |
| 42 |
} |
| 43 |
} |
| 44 |
|
| 45 |
c.JSON(http.StatusOK, gin.H{ |
| 46 |
"Code": proton.SuccessCode, |
| 47 |
}) |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
func validateSendStatReq(req *proton.SendStatsReq) bool { |
| 52 |
return req.MeasurementGroup != "" |
| 53 |
} |