feat: scaffold codespace backend

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
tao.chen
2026-07-02 15:07:54 +08:00
co-authored by Claude Fable 5
commit 411ed1f8ba
43 changed files with 4428 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
package response
import (
"encoding/json"
"net/http"
)
type ErrorBody struct {
Error ErrorDetail `json:"error"`
}
type ErrorDetail struct {
Code string `json:"code"`
Message string `json:"message"`
}
func JSON(w http.ResponseWriter, status int, value any) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(status)
_ = json.NewEncoder(w).Encode(value)
}
func Error(w http.ResponseWriter, status int, code string, err error) {
msg := code
if err != nil {
msg = err.Error()
}
JSON(w, status, ErrorBody{Error: ErrorDetail{Code: code, Message: msg}})
}