go-kit/web/routes.go

28 lines
714 B
Go

// Package web provides the web server for the application.
package web
import (
"fmt"
"net/http"
)
// Routes sets up the routes for the server.
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!")
})
}