Enabled Routes() to accept a prefix
This commit is contained in:
parent
19d9ab1391
commit
92b101dec4
|
@ -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!")
|
||||
|
|
Loading…
Reference in New Issue