relynolli-server/handlers/article/routes.go

27 lines
646 B
Go
Raw Normal View History

2024-05-03 11:57:53 +03:00
package article
import (
"os"
"relynolli-server/handlers/article/endpoints"
"relynolli-server/internal"
"time"
"github.com/gin-contrib/cache"
"github.com/gin-gonic/gin"
)
func HandleRoutes(parent *gin.RouterGroup) {
h := endpoints.GetHandlers()
cacheStore := internal.InitCacheStore()
catalog := parent.Group("/articles")
if os.Getenv("IS_PROD") == "1" {
// Caching for production usage
catalog.GET("", cache.CachePage(cacheStore, 15*time.Minute, h.GetNews))
catalog.GET("/:code", cache.CachePage(cacheStore, 15*time.Minute, h.RetrieveNews))
} else {
catalog.GET("", h.GetNews)
catalog.GET("/:code", h.RetrieveNews)
}
}