123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- package web
- import (
- "fmt"
- "log"
- "net/http"
- "time"
- "github.com/gin-contrib/sessions"
- "github.com/gin-gonic/gin"
- "code.osinet.fr/fgm/sqs_demo/back/services/redriver"
- )
- func makeQueueHandler(rd redriver.Redriver) gin.HandlerFunc {
- return func(c *gin.Context) {
- ctx := c.Request.Context()
- qName := c.Param("name")
- sess := sessions.Default(c)
- flashes := sess.Flashes()
- sess.Clear()
- sess.AddFlash(fmt.Sprintf("Previous info acquired at: %v", time.Now()))
- sess.Save()
- t0 := time.Now()
- qi, err := rd.GetQueueInfo(ctx, qName)
- if err != nil {
- log.Printf("failed getting info for queue %q: %v", qName, err)
- c.JSON(http.StatusInternalServerError, nil)
- return
- }
- infoLatency := time.Since(t0)
- items, err := rd.GetQueueItems(ctx, qName)
- if err != nil {
- log.Printf("failed getting items for queue %q: %v", qName, err)
- c.JSON(http.StatusInternalServerError, nil)
- return
- }
- itemsLatency := time.Since(t0) - infoLatency
- c.HTML(http.StatusOK, "queue-get", map[string]any{
- "flashes": flashes,
- "info": qi,
- "items": items,
- "latency": map[string]time.Duration{
- "info": infoLatency,
- "items": itemsLatency,
- },
- })
- }
- }
|