api calls

This commit is contained in:
2026-09-06 19:14:59 +02:00
parent 13627a369a
commit 2dc9a30644
9 changed files with 1096 additions and 31 deletions
+7 -1
View File
@@ -7,7 +7,7 @@ import (
)
// Error is the single shape every failure takes. Clients get a stable machine
// readable code plus a human message. A self-hosted bot instance can branch on
// readable code plus a human message; a self-hosted bot instance can branch on
// the code without parsing prose.
type Error struct {
Code string `json:"code"`
@@ -46,6 +46,12 @@ func WriteError(w http.ResponseWriter, status int, code, message string) {
}
}
// writeErrorBody writes just the envelope, for callers that have already sent
// their own status code and headers.
func writeErrorBody(w http.ResponseWriter, code, message string) error {
return json.NewEncoder(w).Encode(errorEnvelope{Error{Code: code, Message: message}})
}
// WriteJSON sends a success payload.
func WriteJSON(w http.ResponseWriter, status int, v any) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")