1 parent
952587df4f
commit
efcb19aa2f
19 files changed
+276
-189
No files matched your search
@@ -0,0 +1,18 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Helper to write JSON responses
|
||||
func RespondWithJSON(w http.ResponseWriter, data any, statusCode int) {
|
||||
jsonData, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
http.Error(w, "failed to marshal JSON", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(statusCode)
|
||||
w.Write(jsonData)
|
||||
}
|
||||
Reference in new issue
Block a user