doChecks executes req using c.Client and returns each attempt.
(req *http.Request)
| 123 | |
| 124 | // doChecks executes req using c.Client and returns each attempt. |
| 125 | func (c Checker) doChecks(req *http.Request) types.Attempts { |
| 126 | checks := make(types.Attempts, c.Attempts) |
| 127 | for i := 0; i < c.Attempts; i++ { |
| 128 | start := time.Now() |
| 129 | resp, err := c.Client.Do(req) |
| 130 | checks[i].RTT = time.Since(start) |
| 131 | if err != nil { |
| 132 | checks[i].Error = err.Error() |
| 133 | continue |
| 134 | } |
| 135 | err = c.checkDown(resp) |
| 136 | if err != nil { |
| 137 | checks[i].Error = err.Error() |
| 138 | } |
| 139 | resp.Body.Close() |
| 140 | if c.AttemptSpacing > 0 { |
| 141 | time.Sleep(c.AttemptSpacing) |
| 142 | } |
| 143 | } |
| 144 | return checks |
| 145 | } |
| 146 | |
| 147 | // conclude takes the data in result from the attempts and |
| 148 | // computes remaining values needed to fill out the result. |