queue.go 722 B

123456789101112131415161718192021222324252627282930
  1. package web
  2. import (
  3. "log"
  4. "net/http"
  5. "github.com/gin-gonic/gin"
  6. "code.osinet.fr/fgm/sqs_demo/services/redriver"
  7. )
  8. func makeQueueHandler(rd redriver.Redriver) gin.HandlerFunc {
  9. return func(c *gin.Context) {
  10. ctx := c.Request.Context()
  11. qName := c.Param("name")
  12. qi, err := rd.GetQueueInfo(ctx, qName)
  13. if err != nil {
  14. log.Printf("failed getting info for queue %q: %v", qName, err)
  15. c.JSON(http.StatusInternalServerError, nil)
  16. return
  17. }
  18. items, err := rd.GetQueueItems(ctx, qName)
  19. if err != nil {
  20. log.Printf("failed getting items for queue %q: %v", qName, err)
  21. c.JSON(http.StatusInternalServerError, nil)
  22. return
  23. }
  24. c.JSON(http.StatusOK, map[string]any{"info": qi, "items": items})
  25. }
  26. }