优化 mergeMapList
This commit is contained in:
parent
4b77382218
commit
408995f2b4
16
workflow.go
16
workflow.go
|
@ -197,12 +197,13 @@ func (wf *Workflow) SetBodyParams(params ...interface{}) *Workflow {
|
|||
return wf
|
||||
}
|
||||
|
||||
func mergeMapList(header1, header2 map[string][]string) map[string][]string {
|
||||
func mergeMapList(headers ...map[string][]string) map[string][]string {
|
||||
|
||||
set := make(map[string]map[string]int)
|
||||
merged := make(map[string][]string)
|
||||
|
||||
for key, values := range header1 {
|
||||
for _, header := range headers {
|
||||
for key, values := range header {
|
||||
for _, v := range values {
|
||||
if vs, ok := set[key]; ok {
|
||||
vs[v] = 1
|
||||
|
@ -212,15 +213,6 @@ func mergeMapList(header1, header2 map[string][]string) map[string][]string {
|
|||
}
|
||||
}
|
||||
}
|
||||
for key, values := range header2 {
|
||||
for _, v := range values {
|
||||
if vs, ok := set[key]; ok {
|
||||
vs[v] = 1
|
||||
} else {
|
||||
set[key] = make(map[string]int)
|
||||
set[key][v] = 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for key, mvalue := range set {
|
||||
|
@ -239,7 +231,7 @@ func mergeMapList(header1, header2 map[string][]string) map[string][]string {
|
|||
|
||||
// setHeaderRequest 设置request的头
|
||||
func setHeaderRequest(req *http.Request, wf *Workflow) {
|
||||
req.Header = mergeMapList(req.Header, mergeMapList(wf.session.Header, wf.Header))
|
||||
req.Header = mergeMapList(req.Header, wf.session.Header, wf.Header)
|
||||
}
|
||||
|
||||
// setHeaderRequest 设置request的临时Cookie, 永久需要在session上设置cookie
|
||||
|
|
Loading…
Reference in New Issue
Block a user