feat: sync current progress (P0 hardening + P1 observability + deploy docs/systemd)

This commit is contained in:
OpenClaw Agent
2026-02-28 23:51:23 +08:00
commit d17296d794
96 changed files with 6358 additions and 0 deletions

44
internal/api/response.go Normal file
View File

@@ -0,0 +1,44 @@
package api
import (
"net/http"
"github.com/gin-gonic/gin"
)
type ErrorBody struct {
Code string `json:"code"`
Message string `json:"message"`
Details any `json:"details,omitempty"`
RequestID string `json:"request_id,omitempty"`
}
func requestID(c *gin.Context) string {
if v, ok := c.Get("request_id"); ok {
if s, ok := v.(string); ok {
return s
}
}
return ""
}
func JSONError(c *gin.Context, status int, code, message string, details any) {
c.JSON(status, ErrorBody{
Code: code,
Message: message,
Details: details,
RequestID: requestID(c),
})
}
func JSONBadRequest(c *gin.Context, code, message string, details any) {
JSONError(c, http.StatusBadRequest, code, message, details)
}
func JSONUnauthorized(c *gin.Context, code, message string) {
JSONError(c, http.StatusUnauthorized, code, message, nil)
}
func JSONInternal(c *gin.Context, message string, details any) {
JSONError(c, http.StatusInternalServerError, "INTERNAL_ERROR", message, details)
}