增加getuint64/32的方法

This commit is contained in:
2025-12-07 01:09:52 +08:00
parent 5cfa0d7ce5
commit c589e70f73
3 changed files with 54 additions and 0 deletions

View File

@@ -288,6 +288,8 @@ fac.ParseJSON(r, &req)
// 获取查询参数
id := fac.GetQueryInt64(r, "id", 0)
uid := fac.GetQueryUint64(r, "uid", 0)
userId := fac.GetQueryUint32(r, "user_id", 0)
keyword := fac.GetQuery(r, "keyword", "")
// 获取时区需要配合middleware.Timezone使用
@@ -667,6 +669,14 @@ fac.Success(w, user, "获取成功") // 自定义消息
获取查询64位整数参数。
#### GetQueryUint64(r *http.Request, key string, defaultValue uint64) uint64
获取查询64位无符号整数参数。
#### GetQueryUint32(r *http.Request, key string, defaultValue uint32) uint32
获取查询32位无符号整数参数。
#### GetFormValue(r *http.Request, key, defaultValue string) string
获取表单值。

View File

@@ -984,6 +984,22 @@ func (f *Factory) GetQueryInt64(r *http.Request, key string, defaultValue int64)
return commonhttp.GetQueryInt64(r, key, defaultValue)
}
// GetQueryUint64 获取uint64查询参数黑盒模式推荐使用
// r: HTTP请求
// key: 参数名
// defaultValue: 默认值
func (f *Factory) GetQueryUint64(r *http.Request, key string, defaultValue uint64) uint64 {
return commonhttp.GetQueryUint64(r, key, defaultValue)
}
// GetQueryUint32 获取uint32查询参数黑盒模式推荐使用
// r: HTTP请求
// key: 参数名
// defaultValue: 默认值
func (f *Factory) GetQueryUint32(r *http.Request, key string, defaultValue uint32) uint32 {
return commonhttp.GetQueryUint32(r, key, defaultValue)
}
// GetQueryBool 获取布尔查询参数(黑盒模式,推荐使用)
// r: HTTP请求
// key: 参数名

View File

@@ -223,6 +223,34 @@ func GetQueryFloat64(r *http.Request, key string, defaultValue float64) float64
return floatValue
}
func GetQueryUint64(r *http.Request, key string, defaultValue uint64) uint64 {
value := r.URL.Query().Get(key)
if value == "" {
return defaultValue
}
uintValue, err := strconv.ParseUint(value, 10, 64)
if err != nil {
return defaultValue
}
return uintValue
}
func GetQueryUint32(r *http.Request, key string, defaultValue uint32) uint32 {
value := r.URL.Query().Get(key)
if value == "" {
return defaultValue
}
uintValue, err := strconv.ParseUint(value, 10, 32)
if err != nil {
return defaultValue
}
return uint32(uintValue)
}
// GetFormValue 获取表单值(公共方法)
// r: HTTP请求
// key: 参数名