1234567891011121314151617181920212223242526272829 |
- package myth
- import (
- "net/http"
- "runtime"
- )
- // PanicHandler panic router
- func PanicHandler(w http.ResponseWriter, r *http.Request, err interface{}) {
- var text string
- e, ok := err.(runtime.Error)
- if ok {
- text = e.Error()
- } else {
- text = err.(string)
- }
- WriteJSON(w, ReplyErr(ErrException, text))
- }
- // NotFoundHandler 404
- func NotFoundHandler(w http.ResponseWriter, req *http.Request) {
- WriteJSON(w, ReplyErr(ErrNotFound, `NotFound`))
- }
- // NotAllowedHandler 405
- func NotAllowedHandler(w http.ResponseWriter, req *http.Request) {
- WriteJSON(w, ReplyErr(ErrNotAllowed, `Method Not Allowed`))
- }
|