feat: added healthcheck to server

This commit is contained in:
David Allen 2024-11-21 14:27:22 -07:00 committed by Devon Bautista
parent 7de2dcc4e8
commit b0b52dc432
No known key found for this signature in database
GPG key ID: E1AAD3D4444A3DA0

View file

@ -116,6 +116,7 @@ func (s *Server) Serve() error {
// protected routes if using auth
r.HandleFunc("/generate", s.Generate(opts...))
r.HandleFunc("/status", s.GetStatus)
r.Post("/targets", s.createTarget)
})
} else {
@ -225,6 +226,19 @@ func (s *Server) loadTargets() {
}
}
func (s *Server) GetStatus(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
data := map[string]any{
"code": 200,
"message": "Configurator is healthy",
}
err := json.NewEncoder(w).Encode(data)
if err != nil {
fmt.Printf("failed to encode JSON: %v\n", err)
return
}
}
// Create a new target with name, generator, templates, and files.
//
// Example: