response

package
v0.0.0-...-8c930d8 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const SuccessMsg = "success"

SuccessMsg is the msg of the success envelope, the one JSON writes.

Variables

This section is empty.

Functions

func Abort

func Abort(c *gin.Context, err error)

Abort refuses the request with err, written in the failure envelope the way Error writes it, and stops the handler chain: what code outside the controller path refuses a request through, and nowhere else. A refusal with a status and message of its own is a service error, types.NewError(status, msg), so the one rule NewError holds for statuses and messages holds for every refusal: what the envelope looks like on the wire is the framework's to decide and to change, and a caller here states only the refusal it is making. The public response.Abort forwards to it.

func Attachment

func Attachment(c *gin.Context, data []byte, filename, contentType string)

Attachment writes data as a downloadable file, setting the download file name and content type explicitly. It is used for exports where the format decides the file extension and MIME type.

func Error

func Error(c *gin.Context, err error)

Error writes err in the failure envelope: a service error, anywhere in the wrap chain, answers with the status and client-safe message it was constructed with; any other error is the server's own failure and answers 500 with failureMsg. Internal error text — database drivers naming tables and columns, third-party client output — never reaches the envelope; callers log the full error themselves before answering it here.

func JSON

func JSON(c *gin.Context, data ...any)

JSON writes data in the success envelope: status 200, SuccessMsg, data (null when none is given) and the trace id.

Types

This section is empty.

Jump to

Keyboard shortcuts

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