2019-02-02 16:18:25 +08:00
|
|
|
|
// Copyright 2017 gf Author(https://github.com/gogf/gf). All Rights Reserved.
|
2018-01-11 16:06:42 +08:00
|
|
|
|
//
|
|
|
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
|
|
|
// If a copy of the MIT was not distributed with this file,
|
2019-02-02 16:18:25 +08:00
|
|
|
|
// You can obtain one at https://github.com/gogf/gf.
|
2018-01-11 16:06:42 +08:00
|
|
|
|
|
|
|
|
|
package ghttp
|
|
|
|
|
|
2018-09-26 18:44:30 +08:00
|
|
|
|
import (
|
2019-06-19 09:06:52 +08:00
|
|
|
|
"github.com/gogf/gf/g/encoding/gurl"
|
2019-04-23 20:12:44 +08:00
|
|
|
|
"github.com/gogf/gf/g/util/gconv"
|
|
|
|
|
"strings"
|
2018-09-26 18:44:30 +08:00
|
|
|
|
)
|
2018-01-11 16:06:42 +08:00
|
|
|
|
|
2019-04-23 20:12:44 +08:00
|
|
|
|
// 构建请求参数,参数支持任意数据类型,常见参数类型为string/map。
|
|
|
|
|
// 如果参数为map类型,参数值将会进行urlencode编码。
|
|
|
|
|
func BuildParams(params interface{}) (encodedParamStr string) {
|
|
|
|
|
m := gconv.Map(params)
|
|
|
|
|
if len(m) == 0 {
|
|
|
|
|
return gconv.String(params)
|
|
|
|
|
}
|
|
|
|
|
s := ""
|
2019-06-19 09:06:52 +08:00
|
|
|
|
for k, v := range m {
|
|
|
|
|
if len(encodedParamStr) > 0 {
|
|
|
|
|
encodedParamStr += "&"
|
|
|
|
|
}
|
|
|
|
|
s = gconv.String(v)
|
|
|
|
|
if len(s) > 6 && strings.Compare(s[0:6], "@file:") == 0 {
|
|
|
|
|
encodedParamStr += k + "=" + s
|
|
|
|
|
} else {
|
|
|
|
|
encodedParamStr += k + "=" + gurl.Encode(s)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return
|
|
|
|
|
}
|