CHANGE: Switched The Interface From HTML to JSON API
Build, Push and Deploy CMS / build-push-deploy (push) Successful in 1m53s

This commit is contained in:
FahdShalhoub
2026-08-16 23:15:53 +03:00
parent 8bf0eae425
commit acae765948
14 changed files with 65 additions and 817 deletions
+15 -12
View File
@@ -1,20 +1,23 @@
package handlers
import (
"encoding/json"
"log"
"net/http"
"thamanyah/cms/v2/internal/views"
)
func Home(w http.ResponseWriter, r *http.Request) {
views.Home().Render(r.Context(), w)
}
func Hello(w http.ResponseWriter, r *http.Request) {
views.Greeting("Fahd Shalhoub").Render(r.Context(), w)
}
func Health(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
w.Write([]byte("ok"))
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})
}