2
0

Version 1

This commit is contained in:
MangoPig
2026-06-23 18:50:37 +01:00
commit 55d9772272
133 changed files with 21515 additions and 0 deletions
+30
View File
@@ -0,0 +1,30 @@
package httpx
import (
"encoding/json"
"net/http"
)
type errorEnvelope struct {
Error errorBody `json:"error"`
}
type errorBody struct {
Code string `json:"code"`
Message string `json:"message"`
}
func WriteJSON(w http.ResponseWriter, status int, payload any) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
_ = json.NewEncoder(w).Encode(payload)
}
func WriteError(w http.ResponseWriter, status int, code, message string) {
WriteJSON(w, status, errorEnvelope{
Error: errorBody{
Code: code,
Message: message,
},
})
}