MCPcopy Create free account
hub / github.com/astercloud/aster / JSON

Function JSON

pkg/server/response.go:32–39  ·  view source on GitHub ↗

JSON 辅助函数:发送 JSON 响应

(w http.ResponseWriter, status int, data any)

Source from the content-addressed store, hash-verified

30
31// JSON 辅助函数:发送 JSON 响应
32func JSON(w http.ResponseWriter, status int, data any) {
33 w.Header().Set("Content-Type", "application/json; charset=utf-8")
34 w.WriteHeader(status)
35 _ = json.NewEncoder(w).Encode(&APIResponse{
36 Success: status < 400,
37 Data: data,
38 })
39}
40
41// Error 辅助函数:发送错误响应
42func Error(w http.ResponseWriter, status int, code, message string) {

Callers 2

PaginatedFunction · 0.85
CreatedFunction · 0.85

Calls 1

SetMethod · 0.65

Tested by

no test coverage detected