response

package
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2026 License: MIT Imports: 3 Imported by: 0

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

type ErrorResponse struct {
	Code    string `json:"code"`
	Message string `json:"message"`
}

ErrorResponse is the standard JSON error payload. ErrorResponse 是标准 JSON 错误响应体。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL