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 45 46 47 48 49 50 51 52 53
|
package server
import (
"github.com/gin-gonic/gin"
"github.com/henrybear327/go-proton-api"
"net/http"
)
func (s *Server) handlePostDataStats() gin.HandlerFunc {
return func(c *gin.Context) {
var req proton.SendStatsReq
if err := c.BindJSON(&req); err != nil {
c.AbortWithStatus(http.StatusBadRequest)
return
}
if !validateSendStatReq(&req) {
c.AbortWithStatus(http.StatusBadRequest)
return
}
c.JSON(http.StatusOK, gin.H{
"Code": proton.SuccessCode,
})
}
}
func (s *Server) handlePostDataStatsMultiple() gin.HandlerFunc {
return func(c *gin.Context) {
var req proton.SendStatsMultiReq
if err := c.BindJSON(&req); err != nil {
c.AbortWithStatus(http.StatusBadRequest)
return
}
for _, event := range req.EventInfo {
if !validateSendStatReq(&event) {
c.AbortWithStatus(http.StatusBadRequest)
return
}
}
c.JSON(http.StatusOK, gin.H{
"Code": proton.SuccessCode,
})
}
}
func validateSendStatReq(req *proton.SendStatsReq) bool {
return req.MeasurementGroup != ""
}
|