Files
ops2/backend/ai_work/internal/handler/utils.go
T
2026-04-01 12:09:02 +08:00

35 lines
574 B
Go

package handler
import (
"strconv"
"github.com/gin-gonic/gin"
)
// GetIntParam 获取整数参数
func GetIntParam(c *gin.Context, key string, defaultValue int) int {
value := c.Query(key)
if value == "" {
return defaultValue
}
intValue, err := strconv.Atoi(value)
if err != nil {
return defaultValue
}
return intValue
}
// GetUintParam 获取uint参数
func GetUintParam(c *gin.Context, key string) uint {
value := c.Param(key)
if value == "" {
return 0
}
intValue, err := strconv.Atoi(value)
if err != nil {
return 0
}
return uint(intValue)
}