Skip to content

Commit

Permalink
rewrite of resp check logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaley committed Sep 26, 2016
1 parent 1152d50 commit 821dd58
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions rackhd/proxy/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ func (p *Server) HandleNodes(w http.ResponseWriter, r *http.Request) {
w.Write([]byte(fmt.Sprintf("%s", err)))
return
}
cr, _ := p.GetResp(r, addrMap)
p.RespCheck(w, cr)
ar := p.GetResp(r, addrMap)
p.RespCheck(r, w, ar)
}

// 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(r *http.Request, addrs map[string]struct{}) []Responses {
func (p *Server) GetResp(r *http.Request, addrs map[string]struct{}) Responses {
cr := make(chan *Response, len(addrs))
defer close(cr)

Expand Down Expand Up @@ -107,7 +107,7 @@ func (p *Server) GetResp(r *http.Request, addrs map[string]struct{}) []Responses
}(entry, r)
}
p.wg.Wait()
var ar []Responses
var ar Responses
for entry := range cr {
ar = append(ar, entry)
}
Expand Down Expand Up @@ -160,7 +160,15 @@ func (p *Server) GetQueryAddresses(querySlice []string) map[string]struct{} {

// RespCheck identifies the type of initialResp.Body and calls the appropriate
// helper function to write to the ResponseWriter.
func (p *Server) RespCheck(r *http.Request, w http.ResponseWriter, ar []Response) {
func (p *Server) RespCheck(r *http.Request, w http.ResponseWriter, ar Responses) {

if ar[0].Body != '[' {
w.Write(ar[0].Body)
return
}

// TODO i am re writing this

initialResp := <-cr
if initialResp.Body[0] != '[' {
w.Write(initialResp.Body)
Expand Down

0 comments on commit 821dd58

Please sign in to comment.