diff --git a/http.go b/http.go index b97c322..1cab217 100644 --- a/http.go +++ b/http.go @@ -15,7 +15,7 @@ import ( "time" ) -const Version = "1.0.14" +const Version = "1.0.15" // Response 返回内容 type Response struct { @@ -197,7 +197,7 @@ func request(app *App) (httpResponse Response, err error) { // 赋值 httpResponse.RequestUri = app.httpUri httpResponse.RequestMethod = app.httpMethod - httpResponse.RequestParams = app.httpParams + httpResponse.RequestParams = app.httpParams.DeepCopy() // 请求内容 var reqBody io.Reader diff --git a/params.go b/params.go index c52d32b..caf56c1 100644 --- a/params.go +++ b/params.go @@ -8,11 +8,13 @@ import ( type Params map[string]interface{} +// NewParams 新建参数 func NewParams() Params { P := make(Params) return P } +// NewParamsWith 参数使用 func NewParamsWith(params ...Params) Params { p := make(Params) for _, v := range params { @@ -21,16 +23,19 @@ func NewParamsWith(params ...Params) Params { return p } +// Set 设置参数 func (p Params) Set(key string, value interface{}) { p[key] = value } +// SetParams 批量设置参数 func (p Params) SetParams(params Params) { for key, value := range params { p[key] = value } } +// GetParamsString 获取参数字符串 func GetParamsString(src interface{}) string { switch src.(type) { case string: @@ -46,3 +51,17 @@ func GetParamsString(src interface{}) string { } return string(data) } + +// DeepCopy 深度复制 +func (p *Params) DeepCopy() map[string]interface{} { + targetMap := make(map[string]interface{}) + + // 从原始复制到目标 + for key, value := range *p { + targetMap[key] = value + } + + // 重新申请一个新的map + *p = map[string]interface{}{} + return targetMap +}