From 92b101dec4c19881b4cb7591781cd0c351d49842 Mon Sep 17 00:00:00 2001 From: "Arnaud (Arhuman) ASSAD" Date: Fri, 10 May 2024 08:25:34 +0200 Subject: [PATCH] Enabled Routes() to accept a prefix --- web/routes.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/web/routes.go b/web/routes.go index 47e4997..eb4c833 100644 --- a/web/routes.go +++ b/web/routes.go @@ -7,9 +7,19 @@ import ( ) // Routes sets up the routes for the server. -func (s *Server) Routes() { - s.Log.Info("Health check handler installed") - s.AddRoute("GET /health", func(w http.ResponseWriter, r *http.Request) { +func (s *Server) Routes(prefix string) { + if prefix != "" { + // Ensure the prefix starts with a slash + if prefix[0] != '/' { + prefix = "/" + prefix + } + // Ensure the prefix starts does not end with a slash + if prefix[len(prefix)-1] == '/' { + prefix = prefix[:len(prefix)-1] + } + } + s.Log.Info(fmt.Sprintf("Health check handler installed: %s/health", prefix)) + s.AddRoute("GET $prefix/health", func(w http.ResponseWriter, r *http.Request) { s.Log.Debug("Health check handler called") w.WriteHeader(http.StatusOK) fmt.Fprintf(w, "Hello, World!")