Skip to content

Commit

Permalink
Merge pull request #18 from xujiajun/develop
Browse files Browse the repository at this point in the history
add example for CustomPanicHandler
  • Loading branch information
xujiajun authored Feb 27, 2018
2 parents 9e72568 + 07e1806 commit fa87a96
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions examples/customPanicHandler/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

import (
"fmt"
"github.com/xujiajun/gorouter"
"log"
"net/http"
)

func main() {
mux := gorouter.New()
mux.PanicHandler = func(w http.ResponseWriter, req *http.Request, err interface{}) {
w.WriteHeader(http.StatusInternalServerError)
fmt.Println("err from recover is :", err)
fmt.Fprint(w, "received a panic")
}
mux.GET("/panic", func(w http.ResponseWriter, r *http.Request) {
panic("panic")
})

log.Fatal(http.ListenAndServe(":8181", mux))
}

0 comments on commit fa87a96

Please sign in to comment.