response

package
v1.0.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BadRequest

func BadRequest(c fiber.Ctx, msg string) error

BadRequest helper. BadRequest 辅助函数。

func Conflict

func Conflict(c fiber.Ctx, msg string) error

Conflict helper. Conflict 辅助函数。

func Fail

func Fail(c fiber.Ctx, httpStatus int, code ErrorCode, msg string) error

Fail returns error response. Fail 返回错误响应。

func Forbidden

func Forbidden(c fiber.Ctx, msg string) error

Forbidden helper. Forbidden 辅助函数。

func Internal

func Internal(c fiber.Ctx, msg string) error

Internal helper. Internal 辅助函数。

func NotFound

func NotFound(c fiber.Ctx, msg string) error

NotFound helper. NotFound 辅助函数。

func OK

func OK[T any](c fiber.Ctx, data T) error

OK returns success response. OK 返回成功响应。

func Unauthorized

func Unauthorized(c fiber.Ctx, msg string) error

Unauthorized helper. Unauthorized 辅助函数。

Types

type Envelope

type Envelope[T any] struct {
	Code    ErrorCode `json:"code"`
	Message string    `json:"message"` // English message / 英文信息
	Data    T         `json:"data,omitempty"`
}

Envelope is a unified API response wrapper. Envelope 是统一 API 返回结构。

type ErrorCode

type ErrorCode int

ErrorCode defines unified error codes. ErrorCode 定义统一错误码。

const (
	CodeOK ErrorCode = 0

	CodeBadRequest   ErrorCode = 10000
	CodeUnauthorized ErrorCode = 10001
	CodeForbidden    ErrorCode = 10002
	CodeNotFound     ErrorCode = 10003
	CodeConflict     ErrorCode = 10004
	CodeInternal     ErrorCode = 10005
)

Jump to

Keyboard shortcuts

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