Although @JimB actually answered the question I am posting as it may help someone. I used an anonymous function. Perhaps this could have been done better using closure, but I still haven't figured out how locks work.
req, err = http.NewRequest("GET", URL, nil) cl := http.Client{} var lastUrlQuery string cl.CheckRedirect = func(req *http.Request, via []*http.Request) error { if len(via) > 10 { return errors.New("too many redirects") } lastUrlQuery = req.URL.RequestURI() return nil } resp, err := cl.Do(req) if err != nil { log.Fatal(err) } fmt.Printf("last url query is %v", lastUrlQuery)
source share