http.HandleFunc可以提前中断writer吗?

ohko · · 1815 次点击
func main() { http.HandleFunc("/",Fun1) http.ListenAndServe(":5000",nil) } func Fun1(w http.ResponseWriter, r *http.Request) { _, err := doSomething1() fmt.Println(err) if err != nil { w.WriteHeader(http.StatusBadRequest) fmt.Println("error!") return } doSomething2() w.WriteHeader(http.StatusOK) } func doSomething1()(string,error) { defer func() { if err := recover(); err != nil { fmt.Println("Panic info is: ", err) } }() panic("SimplePanicRecover function panic-ed!") return "abc",errors.New("abc") } func doSomething2() { return }
#2
更多评论