Gofmt recover.go

This commit is contained in:
jordi fita mas 2023-01-22 20:37:34 +01:00
parent 6f2da865c0
commit 7e5e6121ac
1 changed files with 9 additions and 9 deletions

View File

@ -1,10 +1,10 @@
package pkg package pkg
import ( import (
"fmt"
"log"
"net/http" "net/http"
"runtime" "runtime"
"log"
"fmt"
) )
func Recoverer(next http.Handler) http.Handler { func Recoverer(next http.Handler) http.Handler {
@ -12,18 +12,18 @@ func Recoverer(next http.Handler) http.Handler {
defer func() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
if r == http.ErrAbortHandler { if r == http.ErrAbortHandler {
panic(r); panic(r)
} }
err, ok := r.(error) err, ok := r.(error)
if ! ok { if !ok {
err = fmt.Errorf("%v", r); err = fmt.Errorf("%v", r)
} }
stack := make([]byte, 4 << 10); stack := make([]byte, 4<<10)
length := runtime.Stack(stack, true) length := runtime.Stack(stack, true)
log.Printf("PANIC - %v %s", err, stack[:length]) log.Printf("PANIC - %v %s", err, stack[:length])
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
} }
}(); }()
next.ServeHTTP(w, r); next.ServeHTTP(w, r)
}); })
} }