home.go 832 B

12345678910111213141516171819202122232425262728293031323334353637
  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 makeHomeHandler(rd redriver.Redriver) gin.HandlerFunc {
  9. return func(c *gin.Context) {
  10. ctx := c.Request.Context()
  11. qURLs, err := rd.ListQueues(ctx, "test")
  12. if err != nil {
  13. log.Printf("failed listing queues: %v", err)
  14. c.JSON(http.StatusInternalServerError, nil)
  15. return
  16. }
  17. qMap := map[string]string{}
  18. for _, qURL := range qURLs {
  19. name, err := redriver.NameFromURL(qURL)
  20. if err != nil {
  21. log.Println(http.StatusInternalServerError)
  22. c.JSON(http.StatusInternalServerError, nil)
  23. }
  24. dlqURL, err := rd.GetDLQ(ctx, name)
  25. if err != nil {
  26. log.Println(err)
  27. c.JSON(http.StatusInternalServerError, nil)
  28. }
  29. qMap[qURL] = dlqURL
  30. }
  31. c.JSON(http.StatusOK, qMap)
  32. }
  33. }