Skip to content

Commit

Permalink
NewRequest Copy
Browse files Browse the repository at this point in the history
  • Loading branch information
king-jam committed Sep 26, 2016
1 parent b7f2140 commit 2864576
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions rackhd/proxy/controller.go
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,25 @@ func (p *Server) HandleNodes(w http.ResponseWriter, r *http.Request) {
// GetResp makes channels for the response and errors from http.Get.
// A go func is spun up for each http.Get and the responses are fed
// into their respective channels.
func (p *Server) GetResp(pRequest *http.Request, addrs map[string]struct{}) (chan *Response, chan error) {
func (p *Server) GetResp(r *http.Request, addrs map[string]struct{}) (chan *Response, chan error) {
cr := make(chan *Response, len(addrs))
errs := make(chan error, len(addrs))
defer close(cr)
defer close(errs)
var r http.Request
r = *pRequest
for entry := range addrs {
fmt.Printf("Entry => %+v", entry)
r.URL.Host = entry
r.URL.Scheme = "http"
p.wg.Add(1)
go func(r http.Request) {
go func(entry string, r *http.Request) {
defer p.wg.Done()
respGet, err := http.Get(r.URL.String())
fmt.Printf("url string %s\nRESP=> %+v\n\n\n", r.URL.String(), respGet)
url := "http://" + entry + r.URL.Path
req, err := http.NewRequest("GET", url, r.Body)
if err != nil {
errs <- fmt.Errorf("Could not send HTTP Get request to %s => %s\n", r.URL.String(), err)
return
}
client := &http.Client{}
respGet, err := client.Do(req)
fmt.Printf("url string %s\nRESP=> %+v\n\n\n", req.URL.String(), respGet)
if err != nil {
errs <- fmt.Errorf("Could not send HTTP Get request to %s => %s\n", req.URL.String(), err)
return
}
responseCopy, err := NewResponse(respGet)
Expand All @@ -104,7 +105,7 @@ func (p *Server) GetResp(pRequest *http.Request, addrs map[string]struct{}) (cha
}
cr <- responseCopy
respGet.Body.Close()
}(r)
}(entry, r)
}
p.wg.Wait()
return cr, errs
Expand Down

0 comments on commit 2864576

Please sign in to comment.