WriteJSON 写入 JSON 响应
(w http.ResponseWriter, statusCode int, data any)
| 107 | |
| 108 | // WriteJSON 写入 JSON 响应 |
| 109 | func WriteJSON(w http.ResponseWriter, statusCode int, data any) error { |
| 110 | w.Header().Set("Content-Type", "application/json") |
| 111 | w.WriteHeader(statusCode) |
| 112 | return json.NewEncoder(w).Encode(data) |
| 113 | } |
| 114 | |
| 115 | // WriteError 写入错误响应 |
| 116 | func WriteError(w http.ResponseWriter, statusCode int, errCode, message string) error { |
no test coverage detected