Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 545c6ef6a4 | |||
| 5cfa0d7ce5 |
@@ -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
|
||||
|
||||
获取表单值。
|
||||
|
||||
@@ -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: 参数名
|
||||
|
||||
@@ -42,9 +42,10 @@ func getFormInt(r *http.Request, key string, defaultValue int) int {
|
||||
// PaginationRequest 分页请求结构
|
||||
// 支持从JSON和form中解析分页参数
|
||||
type PaginationRequest struct {
|
||||
Page int `json:"page" form:"page"` // 页码,默认1
|
||||
Size int `json:"size" form:"size"` // 每页数量(兼容旧版本)
|
||||
PageSize int `json:"page_size" form:"page_size"` // 每页数量(推荐使用)
|
||||
Page int `json:"page" form:"page"` // 页码,默认1
|
||||
Size int `json:"size" form:"size"` // 每页数量(兼容旧版本)
|
||||
PageSize int `json:"page_size" form:"page_size"` // 每页数量(推荐使用)
|
||||
Keyword string `json:"keyword" form:"keyword"` // 关键字
|
||||
}
|
||||
|
||||
// GetPage 获取页码,如果未设置则返回默认值1
|
||||
@@ -222,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: 参数名
|
||||
|
||||
Reference in New Issue
Block a user