Loggest thy stuff
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
633 B

  1. package api
  2. import (
  3. "git.aiterp.net/stufflog3/stufflog3-api/internal/slerrors"
  4. "github.com/gin-gonic/gin"
  5. "strconv"
  6. )
  7. func handler(key string, callback func(c *gin.Context) (interface{}, error)) gin.HandlerFunc {
  8. return func(c *gin.Context) {
  9. res, err := callback(c)
  10. if err != nil {
  11. slerrors.Respond(c, err)
  12. return
  13. }
  14. resJson := make(map[string]interface{}, 1)
  15. resJson[key] = res
  16. c.JSON(200, resJson)
  17. }
  18. }
  19. func reqInt(c *gin.Context, key string) (int, error) {
  20. v, err := strconv.Atoi(c.Param(key))
  21. if err != nil {
  22. return 0, slerrors.BadRequest(key + " parameter must be a number")
  23. }
  24. return v, nil
  25. }