(w http.ResponseWriter, status int, payload any)
| 863 | } |
| 864 | |
| 865 | func writeJSON(w http.ResponseWriter, status int, payload any) { |
| 866 | w.Header().Set("Content-Type", "application/json; charset=utf-8") |
| 867 | w.WriteHeader(status) |
| 868 | if err := json.NewEncoder(w).Encode(payload); err != nil { |
| 869 | http.Error(w, err.Error(), http.StatusInternalServerError) |
| 870 | } |
| 871 | } |
| 872 | |
| 873 | // internalError 记录完整错误到日志,并向客户端返回通用 500 响应,避免内部细节泄露。 |
| 874 | func internalError(w http.ResponseWriter, r *http.Request, err error) { |
no test coverage detected