This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You never increment the counter. I'd suggest
i += 1
along with thenextUrl
reassignment (line 32)