Documentation
¶
Overview ¶
Package response provides JSON response helpers. Package response 提供 JSON 响应辅助函数。
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WriteJSON ¶
func WriteJSON(w http.ResponseWriter, status int, v any)
WriteJSON writes v as JSON with status. Call WriteJSON(w, status, value). WriteJSON 以 JSON 写入 value 和 status。 调用 WriteJSON(w, status, value)。
Example / 示例:
response.WriteJSON(w, http.StatusOK, map[string]any{"ok": true})
func WriteJSONError ¶
func WriteJSONError(w http.ResponseWriter, status int, code, msg string)
WriteJSONError writes ErrorResponse as JSON. Call WriteJSONError(w, status, code, message). WriteJSONError 以 JSON 写入 ErrorResponse。 调用 WriteJSONError(w, status, code, message)。
Example / 示例:
response.WriteJSONError(w, http.StatusBadRequest, "invalid_json", "invalid json")
Types ¶
type ErrorResponse ¶
ErrorResponse is the standard JSON error payload. ErrorResponse 是标准 JSON 错误响应体。
Click to show internal directories.
Click to hide internal directories.