Files
iknowyou/back/internal/respond/respond.go
2026-04-06 15:12:34 +02:00

19 lines
460 B
Go

package respond
import (
"encoding/json"
"net/http"
)
// JSON writes a JSON body with the given status code.
func JSON(w http.ResponseWriter, status int, payload any) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
_ = json.NewEncoder(w).Encode(payload)
}
// Error writes a JSON error body: {"error": "message"}.
func Error(w http.ResponseWriter, status int, msg string) {
JSON(w, status, map[string]string{"error": msg})
}