response

package
v0.0.0-...-d283dcf Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abort

func Abort(c *gin.Context, status int, msg string)

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

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 Bytes

func Bytes(c *gin.Context, coder types.Coder, data ...[]byte)

func BytesList

func BytesList(c *gin.Context, coder types.Coder, total int, data ...[]byte)

func File

func File(c *gin.Context, filename string)

func JSON

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

func Text

func Text(c *gin.Context, coder types.Coder, data ...any)

Types

type Code

type Code int32

Code is a stable numeric API error code.

const (
	CodeSuccess Code = 0
	CodeFailure Code = -1
)

Success / failure sentinel codes.

const (
	CodeInvalidParam Code = 1000 + iota
	CodeNotFound
	CodeAlreadyExist
	CodeStaleObject
)

General API error codes.

func NewCode

func NewCode(code Code, status int, msg string) Code

func (Code) Code

func (r Code) Code() int

func (Code) Msg

func (r Code) Msg() string

func (Code) Status

func (r Code) Status() int

func (Code) String

func (r Code) String() 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

Jump to

Keyboard shortcuts

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