graphicek/server/routes/utils.go

25 lines
468 B
Go
Raw Normal View History

package routes
import (
"strconv"
"github.com/gin-gonic/gin"
)
func getIntParamOrAbort(c *gin.Context, key string) int64 {
value := c.Param(key)
val, err := strconv.ParseInt(value, 10, 64)
if err != nil {
c.AbortWithStatusJSON(400, gin.H{"error": "Invalid " + key})
}
return val
}
func bindJSONBodyOrAbort(c *gin.Context, body interface{}) {
if err := c.ShouldBindJSON(body); err != nil {
c.AbortWithStatusJSON(400, gin.H{"error": err.Error()})
}
}