rename ngin to rest
This commit is contained in:
22
rest/handler/recoverhandler.go
Normal file
22
rest/handler/recoverhandler.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"runtime/debug"
|
||||
|
||||
"zero/rest/internal"
|
||||
)
|
||||
|
||||
func RecoverHandler(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
defer func() {
|
||||
if result := recover(); result != nil {
|
||||
internal.Error(r, fmt.Sprintf("%v\n%s", result, debug.Stack()))
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
}
|
||||
}()
|
||||
|
||||
next.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user