@@ -3,18 +3,21 @@ package main
33import (
44 "log"
55 "os"
6- "time"
76
87 "github.com/ansrivas/fiberprometheus/v2"
98 "github.com/caarlos0/env/v6"
109 "github.com/gofiber/fiber/v2"
11- "github.com/gofiber/fiber/v2/middleware/cache"
1210 "github.com/gofiber/fiber/v2/middleware/recover"
1311 "github.com/italia/publiccode-validator-api/internal/common"
1412 "github.com/italia/publiccode-validator-api/internal/handlers"
1513 "github.com/italia/publiccode-validator-api/internal/jsondecoder"
1614)
1715
16+ var (
17+ Version = "dev"
18+ Commit = "<none>"
19+ )
20+
1821func main () {
1922 app := Setup ()
2023 if err := app .Listen (":3000" ); err != nil {
@@ -40,19 +43,6 @@ func Setup() *fiber.App {
4043 // Automatically recover panics in handlers
4144 app .Use (recover .New ())
4245
43- app .Use (cache .New (cache.Config {
44- Next : func (ctx * fiber.Ctx ) bool {
45- // Don't cache /status
46- return ctx .Route ().Path == "/v1/status"
47- },
48- Methods : []string {fiber .MethodGet , fiber .MethodHead },
49- CacheControl : true ,
50- Expiration : 10 * time .Second , //nolint:gomnd
51- KeyGenerator : func (ctx * fiber.Ctx ) string {
52- return ctx .Path () + string (ctx .Context ().QueryArgs ().QueryString ())
53- },
54- }))
55-
5646 prometheus := fiberprometheus .New (os .Args [0 ])
5747 prometheus .RegisterAt (app , "/metrics" )
5848 app .Use (prometheus .Middleware )
@@ -64,8 +54,10 @@ func Setup() *fiber.App {
6454
6555func setupHandlers (app * fiber.App ) {
6656 validateHandler := handlers .NewPubliccodeymlValidatorHandler ()
57+ statusHandler := handlers .NewStatus (Version , Commit )
6758
6859 v1 := app .Group ("/v1" )
6960
61+ v1 .Get ("/status" , statusHandler .GetStatus )
7062 v1 .Add ("QUERY" , "/validate" , validateHandler .Query )
7163}
0 commit comments