We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 771c9ff commit 07e1806Copy full SHA for 07e1806
examples/customPanicHandler/main.go
@@ -0,0 +1,22 @@
1
+package main
2
+
3
+import (
4
+ "fmt"
5
+ "github.com/xujiajun/gorouter"
6
+ "log"
7
+ "net/http"
8
+)
9
10
+func main() {
11
+ mux := gorouter.New()
12
+ mux.PanicHandler = func(w http.ResponseWriter, req *http.Request, err interface{}) {
13
+ w.WriteHeader(http.StatusInternalServerError)
14
+ fmt.Println("err from recover is :", err)
15
+ fmt.Fprint(w, "received a panic")
16
+ }
17
+ mux.GET("/panic", func(w http.ResponseWriter, r *http.Request) {
18
+ panic("panic")
19
+ })
20
21
+ log.Fatal(http.ListenAndServe(":8181", mux))
22
+}
0 commit comments