From c0f1c4f137b7b71a4780df34137af143390ec17c Mon Sep 17 00:00:00 2001 From: syntaxsdev Date: Fri, 17 Jan 2025 00:06:02 -0500 Subject: [PATCH] feat: added versioning to log, some cleanup --- internal/api/routes.go | 10 ++++++++++ internal/handlers/logging.go | 2 +- main.go | 2 +- shared/version.go | 3 +++ 4 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 shared/version.go diff --git a/internal/api/routes.go b/internal/api/routes.go index 38423ad..e7593a9 100644 --- a/internal/api/routes.go +++ b/internal/api/routes.go @@ -4,12 +4,22 @@ import ( "net/http" "github.com/go-chi/chi/v5" + "github.com/syntaxsdev/mercury/internal/handlers" "github.com/syntaxsdev/mercury/internal/services" + version "github.com/syntaxsdev/mercury/shared" ) func InitRoutes(factory *services.Factory) http.Handler { r := chi.NewRouter() + // Base endpoint / healthy status + r.Get("/", func(w http.ResponseWriter, r *http.Request) { + handlers.WriteHttp(w, 200, "Mercury is up and running.", map[string]interface{}{ + "status": "healthy", + "version": version.Version, + }) + }) + r.Route("/strategy", func(r chi.Router) { StrategyRoutes(r, factory) }) diff --git a/internal/handlers/logging.go b/internal/handlers/logging.go index 540c108..66e34d9 100644 --- a/internal/handlers/logging.go +++ b/internal/handlers/logging.go @@ -33,7 +33,7 @@ func GetLog(w http.ResponseWriter, r *http.Request, f *services.Factory, n strin WriteHttp(w, http.StatusOK, "Successfully fetched all logs", logs) } -// Create a new log +// Creates a new log func NewLog(w http.ResponseWriter, r *http.Request, f *services.Factory) { var newLog models.Log if err := json.NewDecoder(r.Body).Decode(&newLog); err != nil { diff --git a/main.go b/main.go index 4b02a7e..5af1000 100644 --- a/main.go +++ b/main.go @@ -71,7 +71,7 @@ func main() { // Start Routes router := api.InitRoutes(&factory) - log.Printf("INFO: Starting Server... Listening on http://localhost:%s\n", mercuryPort) + log.Printf("INFO: Starting Server... \nListening on http://localhost:%s\n", mercuryPort) if err := http.ListenAndServe(fmt.Sprintf(":%s", mercuryPort), router); err != nil { log.Fatalf("Serve failed to start: %v", err) } diff --git a/shared/version.go b/shared/version.go new file mode 100644 index 0000000..6ec0073 --- /dev/null +++ b/shared/version.go @@ -0,0 +1,3 @@ +package version + +var Version string = "v1.0.1"