From c3237473c32b0b17f7f1c98df0e993e1aad4ce23 Mon Sep 17 00:00:00 2001 From: Carl Pearson Date: Fri, 30 May 2025 05:59:42 -0600 Subject: [PATCH] Add /about endpoint --- cmd/server/main.go | 14 +++----------- config/config.go | 10 ++++++++++ handlers/about.go | 16 ++++++++++++++++ 3 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 handlers/about.go diff --git a/cmd/server/main.go b/cmd/server/main.go index f5ae649..23028b1 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -12,28 +12,20 @@ import ( ) func main() { - - err := config.Init() - - if err != nil { + if err := config.Init(); err != nil { log.Fatal(err) } - port := config.Port() - e := echo.New() - // Middleware e.Use(middleware.Logger()) e.Use(middleware.Recover()) - // Upload endpoint e.POST("/upload", handlers.UploadPost, handlers.AuthMiddleware) - - // Retrieve endpoint e.GET("/image/:id", handlers.ImageGet, handlers.AuthMiddleware) + e.GET("/about", handlers.AboutGet, handlers.AuthMiddleware) - // Start server + port := config.Port() fmt.Println("Server starting on :" + port) e.Logger.Fatal(e.Start(":" + port)) } diff --git a/config/config.go b/config/config.go index ae143ef..5c89671 100644 --- a/config/config.go +++ b/config/config.go @@ -8,6 +8,8 @@ import ( var bearerToken string var port string +var buildDate string +var gitSHA string func Bearer() string { return bearerToken @@ -17,6 +19,14 @@ func Port() string { return port } +func BuildDate() string { + return buildDate +} + +func GitSHA() string { + return gitSHA +} + func readFromEnv(key string) (string, error) { val, ok := os.LookupEnv(key) if !ok { diff --git a/handlers/about.go b/handlers/about.go new file mode 100644 index 0000000..2e5d296 --- /dev/null +++ b/handlers/about.go @@ -0,0 +1,16 @@ +package handlers + +import ( + "net/http" + + "github.com/labstack/echo/v4" + + "git.sr.ht/~cwpearson/replicate-jump-server/config" +) + +func AboutGet(c echo.Context) error { + return c.JSON(http.StatusOK, map[string]string{ + "version": config.GitSHA(), + "build-date": config.BuildDate(), + }) +}