30 lines
644 B
Go
30 lines
644 B
Go
package handlers_packages
|
|
|
|
import (
|
|
"brunel/domain"
|
|
"brunel/helpers"
|
|
"brunel/packages"
|
|
"time"
|
|
|
|
"github.com/gofiber/fiber/v2"
|
|
)
|
|
|
|
type CountsResponse struct {
|
|
LastUpdateTime time.Time `json:"lastUpdateTime"`
|
|
Counts domain.PackagesCount `json:"counts"`
|
|
}
|
|
|
|
func Counts(c *fiber.Ctx) error {
|
|
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)
|
|
}
|