Documentation
¶
Index ¶
- func Abort(c *gin.Context, status int, msg string)
- func Attachment(c *gin.Context, data []byte, filename, contentType string)
- func Bytes(c *gin.Context, coder types.Coder, data ...[]byte)
- func BytesList(c *gin.Context, coder types.Coder, total int, data ...[]byte)
- func File(c *gin.Context, filename string)
- func JSON(c *gin.Context, coder types.Coder, data ...any)
- func Text(c *gin.Context, coder types.Coder, data ...any)
- type Code
- type CodeInstance
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Abort ¶
Abort refuses the request with status and msg, written in the API envelope, and stops the handler chain.
It exists so that code outside the controller path — middleware, and the middleware a module ships to the projects that copy it — has one way to refuse. Writing the envelope by hand instead works until the envelope grows: the response code recorded just below was added on this path and reached none of the hand-written ones, so every such refusal logged a code its own body contradicted.
func Attachment ¶
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.
Types ¶
type Code ¶
type Code int32
Code is a stable numeric API error code.
General API error codes.
func (Code) String ¶
String renders the code with its message so a Code value logged or formatted directly stays readable instead of printing as a bare integer.
func (Code) WithErr ¶
func (r Code) WithErr(err error) CodeInstance
func (Code) WithMsg ¶
func (r Code) WithMsg(msg string) CodeInstance
func (Code) WithStatus ¶
func (r Code) WithStatus(status int) CodeInstance
type CodeInstance ¶
type CodeInstance struct {
// contains filtered or unexported fields
}
CodeInstance is a Code with optional per-response HTTP status and message overrides. Nil pointer fields mean "use the value from Code (including customCodeValueMap / defaultCodeValueMap)".
func (CodeInstance) Code ¶
func (ci CodeInstance) Code() int
func (CodeInstance) Msg ¶
func (ci CodeInstance) Msg() string
func (CodeInstance) Status ¶
func (ci CodeInstance) Status() int
func (CodeInstance) WithErr ¶
func (ci CodeInstance) WithErr(err error) CodeInstance
func (CodeInstance) WithMsg ¶
func (ci CodeInstance) WithMsg(msg string) CodeInstance
func (CodeInstance) WithStatus ¶
func (ci CodeInstance) WithStatus(status int) CodeInstance