恢复处理程序,以防止服务器崩溃
func Recovery(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request){
defer func() {
if err := recover(); err != nil {
// respondInternalServerError
}
}()
h.ServeHTTP(w , r)
})
}