恢復處理程式,以防止伺服器崩潰
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)
})
}