我有以下代码
package main
import (
"log"
"net/http"
)
func fooHandler(w http.ResponseWriter, r *http.Request) {
// Here an if condition, if should redirect or not
http.Redirect(w, r, "http://www.google.com", 301)
// Do something....
// Call function if redirect was invoked
}
func main() {
http.HandleFunc("/", fooHandler)
err := http.ListenAndServe(":9090", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
}
如何检测重定向是否写在响应对象中?
相关分类