brunel/handlers/packages/counts.go

30 lines
644 B
Go
Raw Normal View History

2024-07-28 20:59:50 +02:00
package handlers_packages
import (
2024-07-29 17:39:11 +02:00
"brunel/domain"
"brunel/helpers"
2024-07-28 20:59:50 +02:00
"brunel/packages"
2024-07-29 17:39:11 +02:00
"time"
2024-07-28 20:59:50 +02:00
"github.com/gofiber/fiber/v2"
)
2024-07-29 17:39:11 +02:00
type CountsResponse struct {
LastUpdateTime time.Time `json:"lastUpdateTime"`
Counts domain.PackagesCount `json:"counts"`
}
2024-07-28 20:59:50 +02:00
func Counts(c *fiber.Ctx) error {
2024-07-29 17:39:11 +02:00
if cachedResponse, ok := helpers.Cache.Get("counts"); ok {
return c.Status(fiber.StatusOK).JSON(cachedResponse)
}
response := CountsResponse{
LastUpdateTime: packages.LastUpdateTime,
Counts: packages.GetPackagesCount(),
}
helpers.Cache.Set("counts", response)
return c.Status(fiber.StatusOK).JSON(response)
2024-07-28 20:59:50 +02:00
}