handler

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const MaxPage = 10000

MaxPage GetPage 允许的最大页码(M-D 修复:防深分页 DoS)。 超大 page 产生超大 OFFSET,大表上为性能灾难/DoS 面。钳制到该上限; 需更深度遍历的业务应改用游标/keyset 分页(框架不内置,避免功能扩张)。

Variables

This section is empty.

Functions

func BadRequest

func BadRequest(c *gin.Context, msg string)

BadRequest 返回参数/请求错误响应。

委托 response.FailWithCode(CodeFail),遵循当前响应模式(ModeBusiness 下 HTTP 200, 错误信息通过 body 中的 code 表达;ModeREST 下 CodeFail 属业务失败不映射 HTTP 错误,仍 200), 并写入 RequestID——与 response 模式系统一致,不再硬编 HTTP 状态码、不再丢失链路追踪。

func BindJSON

func BindJSON(c *gin.Context, req any) error

BindJSON 绑定 JSON 请求

func BindQuery

func BindQuery(c *gin.Context, req any) error

BindQuery 绑定 Query 参数

func FormBool

func FormBool(c *gin.Context, key string, def bool) bool

FormBool 获取 POST 表单参数中的布尔值(带默认值)

func FormFloat64

func FormFloat64(c *gin.Context, key string, def float64) float64

FormFloat64 获取 POST 表单参数中的 float64(带默认值)

func FormInt

func FormInt(c *gin.Context, key string, def int) int

FormInt 获取 POST 表单参数中的整数(带默认值)

func FormInt64

func FormInt64(c *gin.Context, key string, def int64) int64

FormInt64 获取 POST 表单参数中的 int64(带默认值)

func FormString

func FormString(c *gin.Context, key string, def string) string

FormString 获取 POST 表单参数中的字符串(带默认值)

func FormUint64

func FormUint64(c *gin.Context, key string, def uint64) uint64

FormUint64 获取 POST 表单参数中的 uint64(带默认值)

func GetIDFromPath

func GetIDFromPath(c *gin.Context, paramName string) (uint, bool)

GetIDFromPath 从路径获取 ID

func GetPage

func GetPage(c *gin.Context) (int, int)

GetPage 获取分页参数

func HealthCheck

func HealthCheck(c *gin.Context)

HealthCheck 健康检查 @Summary 健康检查 @Description 检查服务是否正常运行 @Tags 系统 @Accept json @Produce json @Success 200 {object} map[string]string @Router /health [get]

响应体与 router.RegisterHealthRoute 收敛为同一 schema(H8d): 恒 200 + {"status":"ok"},不走 response 业务信封,便于 K8s 探针直读。 需要依赖探活(mysql/redis…失败 503)时改用 router.RegisterHealthRoute 传入 checks。

func InternalError

func InternalError(c *gin.Context, msg string)

InternalError 返回服务器错误响应。

委托 response.ServerError(CodeServerError),遵循当前响应模式(ModeBusiness 下 HTTP 200, ModeREST 下 HTTP 500),并写入 RequestID——与 response 模式系统一致, 不再硬编 HTTP 状态码、不再丢失链路追踪。

func ParseInt

func ParseInt(s string, defaultValue int) int

ParseInt 解析整数

func PathInt

func PathInt(c *gin.Context, key string, def int) int

PathInt 从路径参数获取整数(带默认值)

func PathInt64

func PathInt64(c *gin.Context, key string, def int64) int64

PathInt64 从路径参数获取 int64(带默认值)

func PathUint64

func PathUint64(c *gin.Context, key string, def uint64) uint64

PathUint64 从路径参数获取 uint64(带默认值)

func QueryBool

func QueryBool(c *gin.Context, key string, def bool) bool

QueryBool 获取 Query 参数中的布尔值(带默认值)

func QueryFloat64

func QueryFloat64(c *gin.Context, key string, def float64) float64

QueryFloat64 获取 Query 参数中的 float64(带默认值)

func QueryInt

func QueryInt(c *gin.Context, key string, def int) int

QueryInt 获取 Query 参数中的整数(带默认值)

func QueryInt64

func QueryInt64(c *gin.Context, key string, def int64) int64

QueryInt64 获取 Query 参数中的 int64(带默认值)

Types

This section is empty.

Jump to

Keyboard shortcuts

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