1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-25 18:50:55 +00:00

refactor hooks function code

This commit is contained in:
JessonChan 2015-09-17 10:31:53 +08:00
parent c6448727de
commit cce8d1e934

View File

@ -5,6 +5,8 @@ import (
"path/filepath" "path/filepath"
"strconv" "strconv"
"net/http"
"github.com/astaxie/beego/session" "github.com/astaxie/beego/session"
) )
@ -18,42 +20,20 @@ func registerMime() error {
// register default error http handlers, 404,401,403,500 and 503. // register default error http handlers, 404,401,403,500 and 503.
func registerDefaultErrorHandler() error { func registerDefaultErrorHandler() error {
if _, ok := ErrorMaps["401"]; !ok {
ErrorHandler("401", unauthorized)
}
if _, ok := ErrorMaps["402"]; !ok { for e, h := range map[string]func(http.ResponseWriter, *http.Request){
ErrorHandler("402", paymentRequired) "401": unauthorized,
} "402": paymentRequired,
"403": forbidden,
if _, ok := ErrorMaps["403"]; !ok { "404": notFound,
ErrorHandler("403", forbidden) "405": methodNotAllowed,
} "500": internalServerError,
"501": notImplemented,
if _, ok := ErrorMaps["404"]; !ok { "502": badGateway,
ErrorHandler("404", notFound) "503": serviceUnavailable,
} "504": gatewayTimeout,
} {
if _, ok := ErrorMaps["405"]; !ok { ErrorHandler(e, h)
ErrorHandler("405", methodNotAllowed)
}
if _, ok := ErrorMaps["500"]; !ok {
ErrorHandler("500", internalServerError)
}
if _, ok := ErrorMaps["501"]; !ok {
ErrorHandler("501", notImplemented)
}
if _, ok := ErrorMaps["502"]; !ok {
ErrorHandler("502", badGateway)
}
if _, ok := ErrorMaps["503"]; !ok {
ErrorHandler("503", serviceUnavailable)
}
if _, ok := ErrorMaps["504"]; !ok {
ErrorHandler("504", gatewayTimeout)
} }
return nil return nil
} }