Reduce the number of error checks in the generated router.
This commit is contained in:
parent
f90fe99fb3
commit
dcc59e7b86
|
@ -904,27 +904,15 @@ func (router *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, u
|
||||||
case "/overview":
|
case "/overview":
|
||||||
counters.RouteViewCounter.Bump(0)
|
counters.RouteViewCounter.Bump(0)
|
||||||
err = routes.Overview(w,req,user)
|
err = routes.Overview(w,req,user)
|
||||||
if err != nil {
|
|
||||||
router.handleError(err,w,req,user)
|
|
||||||
}
|
|
||||||
case "/pages":
|
case "/pages":
|
||||||
counters.RouteViewCounter.Bump(1)
|
counters.RouteViewCounter.Bump(1)
|
||||||
err = routes.CustomPage(w,req,user,extraData)
|
err = routes.CustomPage(w,req,user,extraData)
|
||||||
if err != nil {
|
|
||||||
router.handleError(err,w,req,user)
|
|
||||||
}
|
|
||||||
case "/forums":
|
case "/forums":
|
||||||
counters.RouteViewCounter.Bump(2)
|
counters.RouteViewCounter.Bump(2)
|
||||||
err = routes.ForumList(w,req,user)
|
err = routes.ForumList(w,req,user)
|
||||||
if err != nil {
|
|
||||||
router.handleError(err,w,req,user)
|
|
||||||
}
|
|
||||||
case "/forum":
|
case "/forum":
|
||||||
counters.RouteViewCounter.Bump(3)
|
counters.RouteViewCounter.Bump(3)
|
||||||
err = routes.ViewForum(w,req,user,extraData)
|
err = routes.ViewForum(w,req,user,extraData)
|
||||||
if err != nil {
|
|
||||||
router.handleError(err,w,req,user)
|
|
||||||
}
|
|
||||||
case "/theme":
|
case "/theme":
|
||||||
err = common.ParseForm(w,req,user)
|
err = common.ParseForm(w,req,user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -934,9 +922,6 @@ func (router *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, u
|
||||||
|
|
||||||
counters.RouteViewCounter.Bump(4)
|
counters.RouteViewCounter.Bump(4)
|
||||||
err = routes.ChangeTheme(w,req,user)
|
err = routes.ChangeTheme(w,req,user)
|
||||||
if err != nil {
|
|
||||||
router.handleError(err,w,req,user)
|
|
||||||
}
|
|
||||||
case "/attachs":
|
case "/attachs":
|
||||||
err = common.ParseForm(w,req,user)
|
err = common.ParseForm(w,req,user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -952,16 +937,10 @@ func (router *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, u
|
||||||
}
|
}
|
||||||
counters.RouteViewCounter.Bump(5)
|
counters.RouteViewCounter.Bump(5)
|
||||||
err = routes.ShowAttachment(w,req,user,extraData)
|
err = routes.ShowAttachment(w,req,user,extraData)
|
||||||
if err != nil {
|
|
||||||
router.handleError(err,w,req,user)
|
|
||||||
}
|
|
||||||
case "/ws":
|
case "/ws":
|
||||||
req.URL.Path += extraData
|
req.URL.Path += extraData
|
||||||
counters.RouteViewCounter.Bump(6)
|
counters.RouteViewCounter.Bump(6)
|
||||||
err = common.RouteWebsockets(w,req,user)
|
err = common.RouteWebsockets(w,req,user)
|
||||||
if err != nil {
|
|
||||||
router.handleError(err,w,req,user)
|
|
||||||
}
|
|
||||||
case "/api":
|
case "/api":
|
||||||
switch(req.URL.Path) {
|
switch(req.URL.Path) {
|
||||||
case "/api/phrases/":
|
case "/api/phrases/":
|
||||||
|
@ -977,9 +956,6 @@ func (router *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, u
|
||||||
counters.RouteViewCounter.Bump(10)
|
counters.RouteViewCounter.Bump(10)
|
||||||
err = routeAPI(w,req,user)
|
err = routeAPI(w,req,user)
|
||||||
}
|
}
|
||||||
if err != nil {
|
|
||||||
router.handleError(err,w,req,user)
|
|
||||||
}
|
|
||||||
case "/report":
|
case "/report":
|
||||||
err = common.NoBanned(w,req,user)
|
err = common.NoBanned(w,req,user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1004,9 +980,6 @@ func (router *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, u
|
||||||
counters.RouteViewCounter.Bump(11)
|
counters.RouteViewCounter.Bump(11)
|
||||||
err = routes.ReportSubmit(w,req,user,extraData)
|
err = routes.ReportSubmit(w,req,user,extraData)
|
||||||
}
|
}
|
||||||
if err != nil {
|
|
||||||
router.handleError(err,w,req,user)
|
|
||||||
}
|
|
||||||
case "/topics":
|
case "/topics":
|
||||||
switch(req.URL.Path) {
|
switch(req.URL.Path) {
|
||||||
case "/topics/create/":
|
case "/topics/create/":
|
||||||
|
@ -1022,9 +995,6 @@ func (router *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, u
|
||||||
counters.RouteViewCounter.Bump(13)
|
counters.RouteViewCounter.Bump(13)
|
||||||
err = routes.TopicList(w,req,user)
|
err = routes.TopicList(w,req,user)
|
||||||
}
|
}
|
||||||
if err != nil {
|
|
||||||
router.handleError(err,w,req,user)
|
|
||||||
}
|
|
||||||
case "/panel":
|
case "/panel":
|
||||||
err = common.SuperModOnly(w,req,user)
|
err = common.SuperModOnly(w,req,user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -1472,9 +1442,6 @@ func (router *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, u
|
||||||
counters.RouteViewCounter.Bump(77)
|
counters.RouteViewCounter.Bump(77)
|
||||||
err = routePanelDashboard(w,req,user)
|
err = routePanelDashboard(w,req,user)
|
||||||
}
|
}
|
||||||
if err != nil {
|
|
||||||
router.handleError(err,w,req,user)
|
|
||||||
}
|
|
||||||
case "/user":
|
case "/user":
|
||||||
switch(req.URL.Path) {
|
switch(req.URL.Path) {
|
||||||
case "/user/edit/":
|
case "/user/edit/":
|
||||||
|
@ -1622,9 +1589,6 @@ func (router *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, u
|
||||||
counters.RouteViewCounter.Bump(89)
|
counters.RouteViewCounter.Bump(89)
|
||||||
err = routes.ViewProfile(w,req,user)
|
err = routes.ViewProfile(w,req,user)
|
||||||
}
|
}
|
||||||
if err != nil {
|
|
||||||
router.handleError(err,w,req,user)
|
|
||||||
}
|
|
||||||
case "/users":
|
case "/users":
|
||||||
switch(req.URL.Path) {
|
switch(req.URL.Path) {
|
||||||
case "/users/ban/submit/":
|
case "/users/ban/submit/":
|
||||||
|
@ -1682,9 +1646,6 @@ func (router *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, u
|
||||||
counters.RouteViewCounter.Bump(93)
|
counters.RouteViewCounter.Bump(93)
|
||||||
err = routes.IPSearch(w,req,user)
|
err = routes.IPSearch(w,req,user)
|
||||||
}
|
}
|
||||||
if err != nil {
|
|
||||||
router.handleError(err,w,req,user)
|
|
||||||
}
|
|
||||||
case "/topic":
|
case "/topic":
|
||||||
switch(req.URL.Path) {
|
switch(req.URL.Path) {
|
||||||
case "/topic/create/submit/":
|
case "/topic/create/submit/":
|
||||||
|
@ -1839,9 +1800,6 @@ func (router *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, u
|
||||||
counters.RouteViewCounter.Bump(103)
|
counters.RouteViewCounter.Bump(103)
|
||||||
err = routes.ViewTopic(w,req,user, extraData)
|
err = routes.ViewTopic(w,req,user, extraData)
|
||||||
}
|
}
|
||||||
if err != nil {
|
|
||||||
router.handleError(err,w,req,user)
|
|
||||||
}
|
|
||||||
case "/reply":
|
case "/reply":
|
||||||
switch(req.URL.Path) {
|
switch(req.URL.Path) {
|
||||||
case "/reply/create/":
|
case "/reply/create/":
|
||||||
|
@ -1916,9 +1874,6 @@ func (router *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, u
|
||||||
counters.RouteViewCounter.Bump(107)
|
counters.RouteViewCounter.Bump(107)
|
||||||
err = routes.ReplyLikeSubmit(w,req,user,extraData)
|
err = routes.ReplyLikeSubmit(w,req,user,extraData)
|
||||||
}
|
}
|
||||||
if err != nil {
|
|
||||||
router.handleError(err,w,req,user)
|
|
||||||
}
|
|
||||||
case "/profile":
|
case "/profile":
|
||||||
switch(req.URL.Path) {
|
switch(req.URL.Path) {
|
||||||
case "/profile/reply/create/":
|
case "/profile/reply/create/":
|
||||||
|
@ -1967,9 +1922,6 @@ func (router *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, u
|
||||||
counters.RouteViewCounter.Bump(110)
|
counters.RouteViewCounter.Bump(110)
|
||||||
err = routes.ProfileReplyDeleteSubmit(w,req,user,extraData)
|
err = routes.ProfileReplyDeleteSubmit(w,req,user,extraData)
|
||||||
}
|
}
|
||||||
if err != nil {
|
|
||||||
router.handleError(err,w,req,user)
|
|
||||||
}
|
|
||||||
case "/poll":
|
case "/poll":
|
||||||
switch(req.URL.Path) {
|
switch(req.URL.Path) {
|
||||||
case "/poll/vote/":
|
case "/poll/vote/":
|
||||||
|
@ -1991,9 +1943,6 @@ func (router *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, u
|
||||||
counters.RouteViewCounter.Bump(112)
|
counters.RouteViewCounter.Bump(112)
|
||||||
err = routes.PollResults(w,req,user,extraData)
|
err = routes.PollResults(w,req,user,extraData)
|
||||||
}
|
}
|
||||||
if err != nil {
|
|
||||||
router.handleError(err,w,req,user)
|
|
||||||
}
|
|
||||||
case "/accounts":
|
case "/accounts":
|
||||||
switch(req.URL.Path) {
|
switch(req.URL.Path) {
|
||||||
case "/accounts/login/":
|
case "/accounts/login/":
|
||||||
|
@ -2048,15 +1997,9 @@ func (router *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, u
|
||||||
counters.RouteViewCounter.Bump(119)
|
counters.RouteViewCounter.Bump(119)
|
||||||
err = routes.AccountRegisterSubmit(w,req,user)
|
err = routes.AccountRegisterSubmit(w,req,user)
|
||||||
}
|
}
|
||||||
if err != nil {
|
|
||||||
router.handleError(err,w,req,user)
|
|
||||||
}
|
|
||||||
/*case "/sitemaps": // TODO: Count these views
|
/*case "/sitemaps": // TODO: Count these views
|
||||||
req.URL.Path += extraData
|
req.URL.Path += extraData
|
||||||
err = sitemapSwitch(w,req)
|
err = sitemapSwitch(w,req)*/
|
||||||
if err != nil {
|
|
||||||
router.handleError(err,w,req,user)
|
|
||||||
}*/
|
|
||||||
case "/uploads":
|
case "/uploads":
|
||||||
if extraData == "" {
|
if extraData == "" {
|
||||||
common.NotFound(w,req,nil)
|
common.NotFound(w,req,nil)
|
||||||
|
@ -2072,6 +2015,7 @@ func (router *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, u
|
||||||
req.URL.Path += extraData
|
req.URL.Path += extraData
|
||||||
// TODO: Find a way to propagate errors up from this?
|
// TODO: Find a way to propagate errors up from this?
|
||||||
router.UploadHandler(w,req) // TODO: Count these views
|
router.UploadHandler(w,req) // TODO: Count these views
|
||||||
|
return
|
||||||
case "":
|
case "":
|
||||||
// Stop the favicons, robots.txt file, etc. resolving to the topics list
|
// Stop the favicons, robots.txt file, etc. resolving to the topics list
|
||||||
// TODO: Add support for favicons and robots.txt files
|
// TODO: Add support for favicons and robots.txt files
|
||||||
|
@ -2117,5 +2061,9 @@ func (router *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, u
|
||||||
}
|
}
|
||||||
counters.RouteViewCounter.Bump(125)
|
counters.RouteViewCounter.Bump(125)
|
||||||
common.NotFound(w,req,nil)
|
common.NotFound(w,req,nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
router.handleError(err,w,req,user)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,10 +75,7 @@ func main() {
|
||||||
for _, item := range route.Vars {
|
for _, item := range route.Vars {
|
||||||
out += "," + item
|
out += "," + item
|
||||||
}
|
}
|
||||||
out += `)
|
out += `)`
|
||||||
if err != nil {
|
|
||||||
router.handleError(err,w,req,user)
|
|
||||||
}`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, group := range routeGroups {
|
for _, group := range routeGroups {
|
||||||
|
@ -148,9 +145,6 @@ func main() {
|
||||||
out += ")"
|
out += ")"
|
||||||
}
|
}
|
||||||
out += `
|
out += `
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
router.handleError(err,w,req,user)
|
|
||||||
}`
|
}`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -680,10 +674,7 @@ func (router *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, u
|
||||||
switch(prefix) {` + out + `
|
switch(prefix) {` + out + `
|
||||||
/*case "/sitemaps": // TODO: Count these views
|
/*case "/sitemaps": // TODO: Count these views
|
||||||
req.URL.Path += extraData
|
req.URL.Path += extraData
|
||||||
err = sitemapSwitch(w,req)
|
err = sitemapSwitch(w,req)*/
|
||||||
if err != nil {
|
|
||||||
router.handleError(err,w,req,user)
|
|
||||||
}*/
|
|
||||||
case "/uploads":
|
case "/uploads":
|
||||||
if extraData == "" {
|
if extraData == "" {
|
||||||
common.NotFound(w,req,nil)
|
common.NotFound(w,req,nil)
|
||||||
|
@ -699,6 +690,7 @@ func (router *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, u
|
||||||
req.URL.Path += extraData
|
req.URL.Path += extraData
|
||||||
// TODO: Find a way to propagate errors up from this?
|
// TODO: Find a way to propagate errors up from this?
|
||||||
router.UploadHandler(w,req) // TODO: Count these views
|
router.UploadHandler(w,req) // TODO: Count these views
|
||||||
|
return
|
||||||
case "":
|
case "":
|
||||||
// Stop the favicons, robots.txt file, etc. resolving to the topics list
|
// Stop the favicons, robots.txt file, etc. resolving to the topics list
|
||||||
// TODO: Add support for favicons and robots.txt files
|
// TODO: Add support for favicons and robots.txt files
|
||||||
|
@ -744,6 +736,10 @@ func (router *GenRouter) routeSwitch(w http.ResponseWriter, req *http.Request, u
|
||||||
}
|
}
|
||||||
counters.RouteViewCounter.Bump({{index .AllRouteMap "routes.BadRoute" }})
|
counters.RouteViewCounter.Bump({{index .AllRouteMap "routes.BadRoute" }})
|
||||||
common.NotFound(w,req,nil)
|
common.NotFound(w,req,nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
router.handleError(err,w,req,user)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
|
|
Loading…
Reference in New Issue