12345678910111213141516171819202122232425262728293031 |
- package web
- import (
- "net/http"
- "runtime"
- "git.chuangxin1.com/cx/tyr"
- )
- // 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, tyr.ErrReplyData(tyr.ErrException, text))
- }
- // NotFoundHandler 404
- func NotFoundHandler(w http.ResponseWriter, req *http.Request) {
- WriteJSON(w, tyr.ErrReplyData(tyr.ErrNotFound, `NotFound`))
- }
- // NotAllowedHandler 405
- func NotAllowedHandler(w http.ResponseWriter, req *http.Request) {
- WriteJSON(w, tyr.ErrReplyData(tyr.ErrNotAllowed, `Method Not Allowed`))
- }
|