-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathconvert.go
42 lines (34 loc) · 806 Bytes
/
convert.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package templatereq
import (
"fmt"
"net/http"
)
func (c *URLReq) ReplaceRequest(r map[string]string) (*http.Response, error) {
headers := make(map[string]string)
for i, j := range c.Headers {
headers[Replace(i, r)] = Replace(j, r)
}
var body interface{}
switch v := c.Body.(type) {
case string:
// v is a string here, so e.g. v + " Yeah!" is possible.
body = Replace(v, r)
case map[string]interface{}:
var bdy = map[string]interface{}{}
for i, j := range v {
bdy[Replace(i, r)] = Replace(fmt.Sprintf("%v", j), r)
}
body = bdy
default:
// And here I'm feeling dumb. ;)
fmt.Printf("I don't know, ask stackoverflow.")
body = c.Body
}
rr := &URLReq{
Url: Replace(c.Url, r),
Method: c.Method,
Body: body,
Headers: headers,
}
return rr.RequestUrl()
}