Files
thamanyah/cms/internal/handlers/handlers.go
T
FahdShalhoub acae765948
Build, Push and Deploy CMS / build-push-deploy (push) Successful in 1m53s
CHANGE: Switched The Interface From HTML to JSON API
2026-08-16 23:15:53 +03:00

24 lines
588 B
Go

package handlers
import (
"encoding/json"
"log"
"net/http"
)
func Health(w http.ResponseWriter, r *http.Request) {
writeJSON(w, http.StatusOK, map[string]string{"status": "ok"})
}
func writeJSON(w http.ResponseWriter, status int, body any) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
if err := json.NewEncoder(w).Encode(body); err != nil {
log.Printf("Something Went Wrong Writing The Response: %s", err)
}
}
func writeJSONError(w http.ResponseWriter, status int, message string) {
writeJSON(w, status, map[string]string{"error": message})
}