add version endpoint (#118)

Co-authored-by: gipsh <gipsh@gmail.com>
This commit is contained in:
gipsh 2023-02-01 10:46:22 -03:00 committed by GitHub
parent cd976bac96
commit 0f47b6d64d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 53 additions and 1 deletions

View File

@ -1,5 +1,23 @@
SHELL := /bin/bash
# These will be provided to the target
GIT := github.com/wormhole-foundation/wormhole-explorer/api/internal/
VERSION := 1.0.0
BUILD := `git rev-parse --short HEAD`
AUTHOR := `whoami`
BUILD_DATE := `date +%Y%m%d%H%M%S`
BRANCH := `git branch --show-current`
MACHINE := `uname -n`
# Use linker flags to provide version/build settings to the target
LDFLAGS=-ldflags "-X=$(GIT)build.Version=$(VERSION)\
-X=$(GIT)build.Time=$(BUILD_DATE)\
-X=$(GIT)build.Build=$(BUILD)\
-X=$(GIT)build.Branch=$(BRANCH)\
-X=$(GIT)build.Machine=$(MACHINE)\
-X=$(GIT)build.User=$(AUTHOR)"
## help: print this help message
.PHONY: help
@ -8,7 +26,7 @@ help:
@sed -n 's/^##//p' ${MAKEFILE_LIST} | column -t -s ':' | sed -e 's/^/ /'
build:
go build -o api main.go
go build -v $(LDFLAGS) -o api main.go
doc:
swag init -pd

View File

@ -0,0 +1,8 @@
package build
var Time string
var User string
var Build string
var Version string
var Branch string
var Machine string

View File

@ -3,6 +3,7 @@ package infrastructure
import (
"github.com/gofiber/fiber/v2"
"github.com/wormhole-foundation/wormhole-explorer/api/handlers/infrastructure"
"github.com/wormhole-foundation/wormhole-explorer/api/internal/build"
)
// Controller definition.
@ -49,3 +50,27 @@ func (c *Controller) ReadyCheck(ctx *fiber.Ctx) error {
Ready string `json:"ready"`
}{Ready: "NO"})
}
// ReadyCheck handler for the endpoint /ready
// ReadyCheck godoc
// @Description Ready check
// @Tags Wormscan
// @ID ready-check
// @Success 200 {object} object{status=string}
// @Failure 400
// @Failure 500
// @Router /api/v1/version [get]
func (c *Controller) Version(ctx *fiber.Ctx) error {
return ctx.JSON(struct {
BuildDate string `json:"build_date"`
Build string `json:"build"`
Branch string `json:"branch"`
Machine string `json:"machine"`
User string `json:"user"`
}{BuildDate: build.Time,
Branch: build.Branch,
Build: build.Build,
Machine: build.Machine,
User: build.User},
)
}

View File

@ -51,6 +51,7 @@ func RegisterRoutes(
// monitoring
api.Get("/health", infrastructureCtrl.HealthCheck)
api.Get("/ready", infrastructureCtrl.ReadyCheck)
api.Get("/version", infrastructureCtrl.Version)
// vaas resource
vaas := api.Group("/vaas")