utils

package
v1.7.1-local.7edcf03 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BindJSONWithValidation

func BindJSONWithValidation(c *gin.Context, req interface{}) bool

BindJSONWithValidation 绑定JSON请求并处理验证错误

func GetQueryWithDefault

func GetQueryWithDefault(c *gin.Context, key, defaultValue string) string

GetQueryWithDefault 获取查询参数,如果不存在则返回默认值

func GetStringParamRequired

func GetStringParamRequired(c *gin.Context, paramName, errorMessage string) (string, bool)

GetStringParamRequired 获取必需的字符串参数,如果为空则返回错误

func GetUsagePercent

func GetUsagePercent(path string) (float64, error)

GetUsagePercent attempts to get disk usage percent for a given path (0-100). Returns error on unsupported platforms or when statfs fails.

func GetUserIDFromContext

func GetUserIDFromContext(c *gin.Context) *uint

GetUserIDFromContext 从gin.Context获取用户ID(如果存在)

func ParseFileFromForm

func ParseFileFromForm(c *gin.Context, fieldName string) (*multipart.FileHeader, bool)

ParseFileFromForm 从表单解析文件,统一错误处理

func ParseIntFromParam

func ParseIntFromParam(c *gin.Context, paramName string, errorMessage string) (int, bool)

ParseIntFromParam 从URL参数解析整数

func ParseUserIDFromParam

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

ParseUserIDFromParam 从URL参数解析用户ID

func ValidateExpireStyle

func ValidateExpireStyle(expireStyle string) bool

ValidateExpireStyle 验证过期样式是否有效

Types

type ExpireParams

type ExpireParams struct {
	ExpireValue int
	ExpireStyle string
	RequireAuth bool
}

ExpireParams 过期参数

func ParseExpireParams

func ParseExpireParams(expireValueStr, expireStyle, requireAuthStr string) (ExpireParams, error)

ParseExpireParams 解析过期参数(支持POST表单和结构体)

type PaginationParams

type PaginationParams struct {
	Page     int
	PageSize int
	Search   string
}

PaginationParams 分页参数

func ParsePaginationParams

func ParsePaginationParams(c *gin.Context) PaginationParams

ParsePaginationParams 解析分页参数

Jump to

Keyboard shortcuts

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