engine refactor
This commit is contained in:
parent
9e663db9dc
commit
81b8e763bd
37 changed files with 3532 additions and 1639 deletions
27
internal/api/httpjson/httpjson.go
Normal file
27
internal/api/httpjson/httpjson.go
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// Package httpjson holds the tiny JSON response helpers shared across
|
||||
// the admin, v2, and async handlers.
|
||||
package httpjson
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
// Write writes body as JSON with the given status code.
|
||||
func Write(w http.ResponseWriter, status int, body any) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(status)
|
||||
_ = json.NewEncoder(w).Encode(body)
|
||||
}
|
||||
|
||||
// Error writes a standard error JSON body with the given status code.
|
||||
//
|
||||
// Shape: {"error": {"type": "...", "description": "..."}}
|
||||
func Error(w http.ResponseWriter, status int, description string) {
|
||||
Write(w, status, map[string]any{
|
||||
"error": map[string]string{
|
||||
"type": http.StatusText(status),
|
||||
"description": description,
|
||||
},
|
||||
})
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue