feat: whole bunch of shit

This commit is contained in:
Max Richter
2025-08-17 16:35:52 +02:00
parent 69c2550f44
commit b3c01bb43d
36 changed files with 878 additions and 12 deletions

View File

@@ -0,0 +1,20 @@
package httpx
import (
"encoding/json"
"net/http"
)
type ErrorResponse struct {
Error string `json:"error"`
}
func WriteJSON(w http.ResponseWriter, code int, v any) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(code)
_ = json.NewEncoder(w).Encode(v)
}
func WriteError(w http.ResponseWriter, code int, err error) {
WriteJSON(w, code, ErrorResponse{Error: err.Error()})
}