This commit is contained in:
2025-07-20 21:22:20 -04:00
parent 349f7fad57
commit 62336753c6
7 changed files with 165 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
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)
}