Files
ai_proxy/server/utils/param.go
2026-03-03 06:05:51 +08:00

27 lines
503 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package utils
import (
"strconv"
"github.com/gin-gonic/gin"
)
// StringToUint 字符串转 uint
func StringToUint(s string) (uint, error) {
val, err := strconv.ParseUint(s, 10, 32)
if err != nil {
return 0, err
}
return uint(val), nil
}
// GetIntQuery 获取查询参数int类型
func GetIntQuery(c *gin.Context, key string, defaultValue int) int {
if val := c.Query(key); val != "" {
if intVal, err := strconv.Atoi(val); err == nil {
return intVal
}
}
return defaultValue
}