mirror of
https://gitee.com/johng/gf.git
synced 2024-12-02 12:17:53 +08:00
improve multipart form parsing for ghttp.Server
This commit is contained in:
parent
6308380541
commit
c492de4fa8
@ -1,14 +1,3 @@
|
||||
# 监控服务主动拉取监控数据配置
|
||||
[active-pulling]
|
||||
# 业务类别 腾讯问诊 订单总数
|
||||
[[active-pulling.tencent-inquiry]]
|
||||
groupId = 3533761
|
||||
metricName = "OrderCount" # 监控项名称
|
||||
url = "http://ylt.medlinker.com/monitor/ordercount" # 监控数据地址
|
||||
interval = "1m" # d:日 h:小时 m:分 s:秒
|
||||
# 业务类别 腾讯问诊 超时订单总数
|
||||
[[active-pulling.tencent-inquiry]]
|
||||
groupId = 3533711
|
||||
metricName = "TimedOutOrderCount"
|
||||
url = "http://ylt.medlinker.com/monitor/timedout-ordercount"
|
||||
interval = "1m"
|
||||
[database]
|
||||
debug = true
|
||||
link = "mysql:root:12345678@tcp(127.0.0.1:3306)/test?parseTime=true&loc=Local"
|
||||
|
@ -1,17 +1,41 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gogf/gf/container/gmap"
|
||||
"github.com/gogf/gf/frame/g"
|
||||
"github.com/gogf/gf/os/glog"
|
||||
)
|
||||
|
||||
func Test(data *gmap.Map) {
|
||||
data = gmap.New()
|
||||
fmt.Println(data)
|
||||
func AddAPKCmdTask11(assistantId int, cmd int32, cmdData []byte, FromClientId string, desc string, priority int, status int32, cmdkey string) (int64, error) {
|
||||
//var res, err = g.DB("test").Insert("assistant_tasks", g.Map{
|
||||
// "assistant_id": assistantId,
|
||||
// "cmd": cmd,
|
||||
// "cmdData": cmdData,
|
||||
// "status": status,
|
||||
// "FromClientId": FromClientId,
|
||||
// "desc": desc,
|
||||
// "priority": priority,
|
||||
// "cmdkey": cmdkey,
|
||||
//})
|
||||
var res, err = g.DB("test").Table("assistant_tasks").Data(g.Map{
|
||||
"assistant_id": assistantId,
|
||||
"cmd": cmd,
|
||||
"cmdData": cmdData,
|
||||
"status": status,
|
||||
"FromClientId": FromClientId,
|
||||
"desc": desc,
|
||||
"priority": priority,
|
||||
"cmdkey": cmdkey,
|
||||
}).Insert()
|
||||
|
||||
if err != nil {
|
||||
glog.Error("插入手机任务队列报错", err.Error())
|
||||
return 0, err
|
||||
}
|
||||
taskId, err := res.LastInsertId()
|
||||
return taskId, err
|
||||
}
|
||||
|
||||
func main() {
|
||||
var m *gmap.Map
|
||||
fmt.Println(m)
|
||||
Test(m)
|
||||
fmt.Println(m)
|
||||
g.DB().SetDebug(true)
|
||||
AddAPKCmdTask11(1, 2058, []byte(""), "", "", 60, 0, "")
|
||||
}
|
||||
|
@ -261,10 +261,8 @@ func handlerSliceArguments(query string, args []interface{}) (newQuery string, n
|
||||
switch kind {
|
||||
// '?'占位符支持slice类型, 这里会将slice参数拆散,并更新原有占位符'?'为多个'?',使用','符号连接。
|
||||
case reflect.Slice, reflect.Array:
|
||||
if rv.Len() == 0 {
|
||||
continue
|
||||
}
|
||||
// 不拆分[]byte类型
|
||||
// 不拆分[]byte类型(当做字符串处理)
|
||||
// Eg: table.Where("name = ?", []byte("john"))
|
||||
if _, ok := arg.([]byte); ok {
|
||||
newArgs = append(newArgs, arg)
|
||||
continue
|
||||
@ -274,6 +272,7 @@ func handlerSliceArguments(query string, args []interface{}) (newQuery string, n
|
||||
}
|
||||
// 如果参数直接传递slice,并且占位符数量与slice长度相等,
|
||||
// 那么不用替换扩展占位符数量,直接使用该slice作为查询参数
|
||||
// Eg: db.Query("SELECT ?+?", g.Slice{1, 2})
|
||||
if len(args) == 1 && gstr.Count(newQuery, "?") == rv.Len() {
|
||||
break
|
||||
}
|
||||
|
@ -210,20 +210,31 @@ func (r *Request) GetHost() string {
|
||||
return r.parsedHost
|
||||
}
|
||||
|
||||
// 获取上传的文件列表
|
||||
func (r *Request) GetMultiPartFiles(name string) []*multipart.FileHeader {
|
||||
// 根据服务端配置解析multipart.Form
|
||||
func (r *Request) parseMultipartForm() *multipart.Form {
|
||||
if !r.parsedForm {
|
||||
r.ParseMultipartForm(r.Server.config.FormParsingMemory)
|
||||
r.parsedForm = true
|
||||
}
|
||||
if r.MultipartForm == nil {
|
||||
return r.MultipartForm
|
||||
}
|
||||
|
||||
// 获取解析后的multipart.Form对象
|
||||
func (r *Request) GetMultipartForm() *multipart.Form {
|
||||
return r.parseMultipartForm()
|
||||
}
|
||||
|
||||
// 获取上传的文件列表
|
||||
func (r *Request) GetMultipartFiles(name string) []*multipart.FileHeader {
|
||||
form := r.GetMultipartForm()
|
||||
if form == nil {
|
||||
return nil
|
||||
}
|
||||
if v := r.MultipartForm.File[name]; len(v) > 0 {
|
||||
if v := form.File[name]; len(v) > 0 {
|
||||
return v
|
||||
}
|
||||
// Support "name[]" as array parameter.
|
||||
if v := r.MultipartForm.File[name+"[]"]; len(v) > 0 {
|
||||
if v := form.File[name+"[]"]; len(v) > 0 {
|
||||
return v
|
||||
}
|
||||
return nil
|
||||
|
@ -22,10 +22,7 @@ func (r *Request) initPost() {
|
||||
r.parsedPost = true
|
||||
if v := r.Header.Get("Content-Type"); v != "" && gstr.Contains(v, "multipart/") {
|
||||
// multipart/form-data, multipart/mixed
|
||||
if !r.parsedForm {
|
||||
r.ParseMultipartForm(r.Server.config.FormParsingMemory)
|
||||
r.parsedForm = true
|
||||
}
|
||||
r.parseMultipartForm()
|
||||
if len(r.PostForm) > 0 {
|
||||
// 重新组织数据格式,使用统一的数据Parse方式
|
||||
params := ""
|
||||
|
Loading…
Reference in New Issue
Block a user