sendJSON 发送 JSON 响应
(w http.ResponseWriter, data any)
| 230 | |
| 231 | // sendJSON 发送 JSON 响应 |
| 232 | func (s *HTTPBridgeServer) sendJSON(w http.ResponseWriter, data any) { |
| 233 | w.Header().Set("Content-Type", "application/json") |
| 234 | w.WriteHeader(http.StatusOK) |
| 235 | if err := json.NewEncoder(w).Encode(data); err != nil { |
| 236 | // 无法发送错误响应给客户端,仅记录日志 |
| 237 | fmt.Fprintf(os.Stderr, "Failed to encode JSON response: %v\n", err) |
| 238 | } |
| 239 | } |
| 240 | |
| 241 | // sendError 发送错误响应 |
| 242 | func (s *HTTPBridgeServer) sendError(w http.ResponseWriter, message string, statusCode int) { |
no test coverage detected