Documentation
¶
Index ¶
- Constants
- func BadRequest(c *gin.Context, msg string)
- func BindJSON(c *gin.Context, req any) error
- func BindJSONWithMaxBytes(c *gin.Context, req any, maxBytes int64) error
- func BindQuery(c *gin.Context, req any) error
- func FormBool(c *gin.Context, key string, def bool) bool
- func FormFloat64(c *gin.Context, key string, def float64) float64
- func FormInt(c *gin.Context, key string, def int) int
- func FormInt64(c *gin.Context, key string, def int64) int64
- func FormString(c *gin.Context, key string, def string) string
- func FormUint64(c *gin.Context, key string, def uint64) uint64
- func GetIDFromPath(c *gin.Context, paramName string) (uint, bool)
- func GetPage(c *gin.Context) (int, int)
- func HealthCheck(c *gin.Context)
- func InternalError(c *gin.Context, msg string)
- func ParseInt(s string, defaultValue int) int
- func PathInt(c *gin.Context, key string, def int) int
- func PathInt64(c *gin.Context, key string, def int64) int64
- func PathUint64(c *gin.Context, key string, def uint64) uint64
- func QueryBool(c *gin.Context, key string, def bool) bool
- func QueryFloat64(c *gin.Context, key string, def float64) float64
- func QueryInt(c *gin.Context, key string, def int) int
- func QueryInt64(c *gin.Context, key string, def int64) int64
Constants ¶
const DefaultMaxJSONBodyBytes int64 = 1 << 20 // 1 MiB
DefaultMaxJSONBodyBytes 是 BindJSON 的默认请求体上限。 入口层无上限读 JSON 会让任意 handler 暴露 OOM 面;需要更大请求体的业务可改用 BindJSONWithMaxBytes 显式声明上限。
const MaxPage = 10000
MaxPage GetPage 允许的最大页码(M-D 修复:防深分页 DoS)。 超大 page 产生超大 OFFSET,大表上为性能灾难/DoS 面。钳制到该上限; 需更深度遍历的业务应改用游标/keyset 分页(框架不内置,避免功能扩张)。
Variables ¶
This section is empty.
Functions ¶
func BadRequest ¶
BadRequest 返回参数/请求错误响应。
委托 response.FailWithCode(CodeFail),遵循当前响应模式(ModeBusiness 下 HTTP 200, 错误信息通过 body 中的 code 表达;ModeREST 下 CodeFail 属业务失败不映射 HTTP 错误,仍 200), 并写入 RequestID——与 response 模式系统一致,不再硬编 HTTP 状态码、不再丢失链路追踪。
func BindJSONWithMaxBytes ¶ added in v1.3.0
BindJSONWithMaxBytes 绑定 JSON 请求,并限制最大 body 大小。 maxBytes<=0 时返回明确错误,避免 http.MaxBytesReader 的非正上限产生不可读语义。
func FormFloat64 ¶
FormFloat64 获取 POST 表单参数中的 float64(带默认值)
func FormString ¶
FormString 获取 POST 表单参数中的字符串(带默认值)
func FormUint64 ¶
FormUint64 获取 POST 表单参数中的 uint64(带默认值)
func GetIDFromPath ¶
GetIDFromPath 从路径获取 ID
func HealthCheck ¶
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 ¶
InternalError 返回服务器错误响应。
委托 response.ServerError(CodeServerError),遵循当前响应模式(ModeBusiness 下 HTTP 200, ModeREST 下 HTTP 500),并写入 RequestID——与 response 模式系统一致, 不再硬编 HTTP 状态码、不再丢失链路追踪。
func PathUint64 ¶
PathUint64 从路径参数获取 uint64(带默认值)
func QueryFloat64 ¶
QueryFloat64 获取 Query 参数中的 float64(带默认值)
Types ¶
This section is empty.