Files
orphanage/client/httputil/response.go
2025-07-20 21:22:20 -04:00

18 lines
366 B
Go

package httputil
import (
"encoding/json"
"net/http"
)
func WriteJSON(w http.ResponseWriter, status int, data interface{}) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
jsonBytes, err := json.Marshal(data)
if err != nil {
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}
w.Write(jsonBytes)
}