core/crm-core/internal/api/http/response.go
2025-12-27 14:32:00 -03:00

23 lines
470 B
Go

package httpapi
import (
"encoding/json"
"net/http"
)
type ErrorResponse struct {
Message string `json:"message"`
}
func RespondJSON(w http.ResponseWriter, status int, payload any) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
if payload == nil {
return
}
_ = json.NewEncoder(w).Encode(payload)
}
func RespondError(w http.ResponseWriter, status int, message string) {
RespondJSON(w, status, ErrorResponse{Message: message})
}