Skip to content

Instantly share code, notes, and snippets.

@alexellis

alexellis/app.go Secret

Created February 27, 2017 13:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alexellis/9b0fc4198dc772e899de7da5a251cef0 to your computer and use it in GitHub Desktop.
Save alexellis/9b0fc4198dc772e899de7da5a251cef0 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"net/http"
)
func main() {
myURL := "http://www.jonathanmh.com"
nextURL := myURL
var i int
client := &http.Client{
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
}}
for i < 100 {
resp, err := client.Get(nextURL)
if err != nil {
fmt.Println(err)
}
fmt.Println("StatusCode:", resp.StatusCode)
fmt.Println(resp.Request.URL)
if resp.StatusCode == 200 {
fmt.Println("Done!")
break
} else {
nextURL = resp.Header.Get("Location")
}
}
}
@willf
Copy link

willf commented Jun 6, 2017

You never increment the counter. I'd suggest i += 1 along with the nextUrl reassignment (line 32)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment