handler.go 608 B

1234567891011121314151617181920212223242526272829
  1. package myth
  2. import (
  3. "net/http"
  4. "runtime"
  5. )
  6. // PanicHandler panic router
  7. func PanicHandler(w http.ResponseWriter, r *http.Request, err interface{}) {
  8. var text string
  9. e, ok := err.(runtime.Error)
  10. if ok {
  11. text = e.Error()
  12. } else {
  13. text = err.(string)
  14. }
  15. WriteJSON(w, ReplyErr(ErrException, text))
  16. }
  17. // NotFoundHandler 404
  18. func NotFoundHandler(w http.ResponseWriter, req *http.Request) {
  19. WriteJSON(w, ReplyErr(ErrNotFound, `NotFound`))
  20. }
  21. // NotAllowedHandler 405
  22. func NotAllowedHandler(w http.ResponseWriter, req *http.Request) {
  23. WriteJSON(w, ReplyErr(ErrNotAllowed, `Method Not Allowed`))
  24. }