response

package
v0.1.3 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. 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 code. WriteJSON 以 JSON 格式写入响应。

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 a standard JSON error. WriteJSONError 写入标准 JSON 错误响应。

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 error payload. ErrorResponse 是标准错误响应体。

Jump to

Keyboard shortcuts

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