Scaffolding baseline
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const Version = "0.1.0"
|
||||
|
||||
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,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user