35 lines
766 B
Go
35 lines
766 B
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
)
|
|
|
|
const Version = "0.0.1"
|
|
|
|
type healthResponse struct {
|
|
Status string `json:"status"`
|
|
}
|
|
|
|
type statusResponse struct {
|
|
Service string `json:"service"`
|
|
Version string `json:"version"`
|
|
}
|
|
|
|
func writeJSON(writer http.ResponseWriter, statusCode int, payload any) {
|
|
writer.Header().Set("Content-Type", "application/json")
|
|
writer.WriteHeader(statusCode)
|
|
_ = json.NewEncoder(writer).Encode(payload)
|
|
}
|
|
|
|
func HealthHandler(writer http.ResponseWriter, request *http.Request) {
|
|
writeJSON(writer, http.StatusOK, healthResponse{Status: "ok"})
|
|
}
|
|
|
|
func StatusHandler(writer http.ResponseWriter, request *http.Request) {
|
|
writeJSON(writer, http.StatusOK, statusResponse{
|
|
Service: "clustercanvas",
|
|
Version: Version,
|
|
})
|
|
}
|