调整request的方法,增加类型转换的方法
This commit is contained in:
@@ -927,7 +927,7 @@ func (f *Factory) SystemError(w http.ResponseWriter, message string) {
|
||||
// ========== HTTP请求解析方法(黑盒模式,推荐使用) ==========
|
||||
//
|
||||
// 这些方法直接调用 http 包的公共方法,保持低耦合。
|
||||
// 推荐直接使用 factory.ParseJSON()、factory.GetQuery() 等方法。
|
||||
// 推荐直接使用 factory.ParseJSON()、factory.ConvertInt() 等方法。
|
||||
|
||||
// ParseJSON 解析JSON请求体(黑盒模式,推荐使用)
|
||||
// r: HTTP请求
|
||||
@@ -960,100 +960,46 @@ func (f *Factory) ParsePaginationRequest(r *http.Request) *PaginationRequest {
|
||||
return commonhttp.ParsePaginationRequest(r)
|
||||
}
|
||||
|
||||
// GetQuery 获取查询参数(字符串)(黑盒模式,推荐使用)
|
||||
// r: HTTP请求
|
||||
// key: 参数名
|
||||
// defaultValue: 默认值
|
||||
func (f *Factory) GetQuery(r *http.Request, key, defaultValue string) string {
|
||||
return commonhttp.GetQuery(r, key, defaultValue)
|
||||
// ConvertInt 将字符串转换为int类型(黑盒模式,推荐使用)
|
||||
// value: 待转换的字符串
|
||||
// defaultValue: 转换失败或字符串为空时返回的默认值
|
||||
func (f *Factory) ConvertInt(value string, defaultValue int) int {
|
||||
return tools.ConvertInt(value, defaultValue)
|
||||
}
|
||||
|
||||
// GetQueryInt 获取整数查询参数(黑盒模式,推荐使用)
|
||||
// r: HTTP请求
|
||||
// key: 参数名
|
||||
// defaultValue: 默认值
|
||||
func (f *Factory) GetQueryInt(r *http.Request, key string, defaultValue int) int {
|
||||
return commonhttp.GetQueryInt(r, key, defaultValue)
|
||||
// ConvertInt64 将字符串转换为int64类型(黑盒模式,推荐使用)
|
||||
// value: 待转换的字符串
|
||||
// defaultValue: 转换失败或字符串为空时返回的默认值
|
||||
func (f *Factory) ConvertInt64(value string, defaultValue int64) int64 {
|
||||
return tools.ConvertInt64(value, defaultValue)
|
||||
}
|
||||
|
||||
// GetQueryInt64 获取int64查询参数(黑盒模式,推荐使用)
|
||||
// r: HTTP请求
|
||||
// key: 参数名
|
||||
// defaultValue: 默认值
|
||||
func (f *Factory) GetQueryInt64(r *http.Request, key string, defaultValue int64) int64 {
|
||||
return commonhttp.GetQueryInt64(r, key, defaultValue)
|
||||
// ConvertUint64 将字符串转换为uint64类型(黑盒模式,推荐使用)
|
||||
// value: 待转换的字符串
|
||||
// defaultValue: 转换失败或字符串为空时返回的默认值
|
||||
func (f *Factory) ConvertUint64(value string, defaultValue uint64) uint64 {
|
||||
return tools.ConvertUint64(value, 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)
|
||||
// ConvertUint32 将字符串转换为uint32类型(黑盒模式,推荐使用)
|
||||
// value: 待转换的字符串
|
||||
// defaultValue: 转换失败或字符串为空时返回的默认值
|
||||
func (f *Factory) ConvertUint32(value string, defaultValue uint32) uint32 {
|
||||
return tools.ConvertUint32(value, 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)
|
||||
// ConvertBool 将字符串转换为bool类型(黑盒模式,推荐使用)
|
||||
// value: 待转换的字符串
|
||||
// defaultValue: 转换失败或字符串为空时返回的默认值
|
||||
func (f *Factory) ConvertBool(value string, defaultValue bool) bool {
|
||||
return tools.ConvertBool(value, defaultValue)
|
||||
}
|
||||
|
||||
// GetQueryBool 获取布尔查询参数(黑盒模式,推荐使用)
|
||||
// r: HTTP请求
|
||||
// key: 参数名
|
||||
// defaultValue: 默认值
|
||||
func (f *Factory) GetQueryBool(r *http.Request, key string, defaultValue bool) bool {
|
||||
return commonhttp.GetQueryBool(r, key, defaultValue)
|
||||
}
|
||||
|
||||
// GetQueryFloat64 获取float64查询参数(黑盒模式,推荐使用)
|
||||
// r: HTTP请求
|
||||
// key: 参数名
|
||||
// defaultValue: 默认值
|
||||
func (f *Factory) GetQueryFloat64(r *http.Request, key string, defaultValue float64) float64 {
|
||||
return commonhttp.GetQueryFloat64(r, key, defaultValue)
|
||||
}
|
||||
|
||||
// GetFormValue 获取表单值(字符串)(黑盒模式,推荐使用)
|
||||
// r: HTTP请求
|
||||
// key: 参数名
|
||||
// defaultValue: 默认值
|
||||
func (f *Factory) GetFormValue(r *http.Request, key, defaultValue string) string {
|
||||
return commonhttp.GetFormValue(r, key, defaultValue)
|
||||
}
|
||||
|
||||
// GetFormInt 获取表单整数(黑盒模式,推荐使用)
|
||||
// r: HTTP请求
|
||||
// key: 参数名
|
||||
// defaultValue: 默认值
|
||||
func (f *Factory) GetFormInt(r *http.Request, key string, defaultValue int) int {
|
||||
return commonhttp.GetFormInt(r, key, defaultValue)
|
||||
}
|
||||
|
||||
// GetFormInt64 获取表单int64(黑盒模式,推荐使用)
|
||||
// r: HTTP请求
|
||||
// key: 参数名
|
||||
// defaultValue: 默认值
|
||||
func (f *Factory) GetFormInt64(r *http.Request, key string, defaultValue int64) int64 {
|
||||
return commonhttp.GetFormInt64(r, key, defaultValue)
|
||||
}
|
||||
|
||||
// GetFormBool 获取表单布尔值(黑盒模式,推荐使用)
|
||||
// r: HTTP请求
|
||||
// key: 参数名
|
||||
// defaultValue: 默认值
|
||||
func (f *Factory) GetFormBool(r *http.Request, key string, defaultValue bool) bool {
|
||||
return commonhttp.GetFormBool(r, key, defaultValue)
|
||||
}
|
||||
|
||||
// GetHeader 获取请求头(黑盒模式,推荐使用)
|
||||
// r: HTTP请求
|
||||
// key: 请求头名称
|
||||
// defaultValue: 默认值
|
||||
func (f *Factory) GetHeader(r *http.Request, key, defaultValue string) string {
|
||||
return commonhttp.GetHeader(r, key, defaultValue)
|
||||
// ConvertFloat64 将字符串转换为float64类型(黑盒模式,推荐使用)
|
||||
// value: 待转换的字符串
|
||||
// defaultValue: 转换失败或字符串为空时返回的默认值
|
||||
func (f *Factory) ConvertFloat64(value string, defaultValue float64) float64 {
|
||||
return tools.ConvertFloat64(value, defaultValue)
|
||||
}
|
||||
|
||||
// GetTimezone 从请求的context中获取时区(黑盒模式,推荐使用)
|
||||
|
||||
Reference in New Issue
Block a user