diff --git a/gen_router.go b/gen_router.go index 6d9dabd7..4c7bb8c9 100644 --- a/gen_router.go +++ b/gen_router.go @@ -65,12 +65,36 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { return case "/topics": switch(req.URL.Path) { - case "/topics/": - route_topics(w,req) - return case "/topics/create/": route_topic_create(w,req, extra_data) return + default: + route_topics(w,req) + return + } + case "/panel": + switch(req.URL.Path) { + case "/panel/forums/": + route_panel_forums(w,req) + return + case "/panel/forums/create/": + route_panel_forums_create_submit(w,req) + return + case "/panel/forums/delete/": + route_panel_forums_delete(w,req, extra_data) + return + case "/panel/forums/delete/submit/": + route_panel_forums_delete_submit(w,req, extra_data) + return + case "/panel/forums/edit/": + route_panel_forums_edit(w,req, extra_data) + return + case "/panel/forums/edit/submit/": + route_panel_forums_edit_submit(w,req, extra_data) + return + default: + route_panel(w,req) + return } case "/uploads": if extra_data == "" { diff --git a/main.go b/main.go index e45c6b21..f8ff2523 100644 --- a/main.go +++ b/main.go @@ -239,14 +239,14 @@ func main(){ router.HandleFunc("/users/unban/", route_unban) router.HandleFunc("/users/activate/", route_activate) - // Admin - router.HandleFunc("/panel/", route_panel) - router.HandleFunc("/panel/forums/", route_panel_forums) - router.HandleFunc("/panel/forums/create/", route_panel_forums_create_submit) - router.HandleFunc("/panel/forums/delete/", route_panel_forums_delete) - router.HandleFunc("/panel/forums/delete/submit/", route_panel_forums_delete_submit) - router.HandleFunc("/panel/forums/edit/", route_panel_forums_edit) - router.HandleFunc("/panel/forums/edit/submit/", route_panel_forums_edit_submit) + // The Control Panel + ///router.HandleFunc("/panel/", route_panel) + ///router.HandleFunc("/panel/forums/", route_panel_forums) + ///router.HandleFunc("/panel/forums/create/", route_panel_forums_create_submit) + ///router.HandleFunc("/panel/forums/delete/", route_panel_forums_delete) + ///router.HandleFunc("/panel/forums/delete/submit/", route_panel_forums_delete_submit) + ///router.HandleFunc("/panel/forums/edit/", route_panel_forums_edit) + ///router.HandleFunc("/panel/forums/edit/submit/", route_panel_forums_edit_submit) router.HandleFunc("/panel/settings/", route_panel_settings) router.HandleFunc("/panel/settings/edit/", route_panel_setting) router.HandleFunc("/panel/settings/edit/submit/", route_panel_setting_edit) diff --git a/panel_routes.go b/panel_routes.go index a9f6e3eb..314e981f 100644 --- a/panel_routes.go +++ b/panel_routes.go @@ -85,7 +85,7 @@ func route_panel_forums_create_submit(w http.ResponseWriter, r *http.Request){ http.Redirect(w,r,"/panel/forums/",http.StatusSeeOther) } -func route_panel_forums_delete(w http.ResponseWriter, r *http.Request){ +func route_panel_forums_delete(w http.ResponseWriter, r *http.Request, sfid string){ user, noticeList, ok := SessionCheck(w,r) if !ok { return @@ -99,7 +99,7 @@ func route_panel_forums_delete(w http.ResponseWriter, r *http.Request){ return } - fid, err := strconv.Atoi(r.URL.Path[len("/panel/forums/delete/"):]) + fid, err := strconv.Atoi(sfid) if err != nil { LocalError("The provided Forum ID is not a valid number.",w,r,user) return @@ -117,7 +117,7 @@ func route_panel_forums_delete(w http.ResponseWriter, r *http.Request){ templates.ExecuteTemplate(w,"areyousure.html",pi) } -func route_panel_forums_delete_submit(w http.ResponseWriter, r *http.Request) { +func route_panel_forums_delete_submit(w http.ResponseWriter, r *http.Request, sfid string) { user, ok := SimpleSessionCheck(w,r) if !ok { return @@ -131,7 +131,7 @@ func route_panel_forums_delete_submit(w http.ResponseWriter, r *http.Request) { return } - fid, err := strconv.Atoi(r.URL.Path[len("/panel/forums/delete/submit/"):]) + fid, err := strconv.Atoi(sfid) if err != nil { LocalError("The provided Forum ID is not a valid number.",w,r,user) return @@ -149,7 +149,7 @@ func route_panel_forums_delete_submit(w http.ResponseWriter, r *http.Request) { http.Redirect(w,r,"/panel/forums/",http.StatusSeeOther) } -func route_panel_forums_edit(w http.ResponseWriter, r *http.Request) { +func route_panel_forums_edit(w http.ResponseWriter, r *http.Request, sfid string) { user, noticeList, ok := SessionCheck(w,r) if !ok { return @@ -159,7 +159,7 @@ func route_panel_forums_edit(w http.ResponseWriter, r *http.Request) { return } - fid, err := strconv.Atoi(r.URL.Path[len("/panel/forums/edit/"):]) + fid, err := strconv.Atoi(sfid) if err != nil { LocalError("The provided Forum ID is not a valid number.",w,r,user) return @@ -173,7 +173,7 @@ func route_panel_forums_edit(w http.ResponseWriter, r *http.Request) { templates.ExecuteTemplate(w,"panel-forum-edit.html",pi) } -func route_panel_forums_edit_submit(w http.ResponseWriter, r *http.Request) { +func route_panel_forums_edit_submit(w http.ResponseWriter, r *http.Request, sfid string) { user, ok := SimpleSessionCheck(w,r) if !ok { return @@ -197,7 +197,7 @@ func route_panel_forums_edit_submit(w http.ResponseWriter, r *http.Request) { is_js = "0" } - fid, err := strconv.Atoi(r.URL.Path[len("/panel/forums/edit/submit/"):]) + fid, err := strconv.Atoi(sfid) if err != nil { LocalErrorJSQ("The provided Forum ID is not a valid number.",w,r,user,is_js) return diff --git a/router_gen/main.go b/router_gen/main.go index 4090f331..5717e861 100644 --- a/router_gen/main.go +++ b/router_gen/main.go @@ -46,7 +46,13 @@ func main() { out += ` case "` + group.Path[0:end] + `": switch(req.URL.Path) {` + var default_route Route for _, route := range group.Routes { + if group.Path == route.Path { + default_route = route + continue + } + out += "\n\t\t\t\tcase \"" + route.Path + "\":" if route.Before != "" { out += "\n\t\t\t\t\t" + route.Before @@ -57,6 +63,18 @@ func main() { } out += ")\n\t\t\t\t\treturn" } + + if default_route.Name != "" { + out += "\n\t\t\t\tdefault:" + if default_route.Before != "" { + out += "\n\t\t\t\t\t" + default_route.Before + } + out += "\n\t\t\t\t\t" + default_route.Name + "(w,req" + for _, item := range default_route.Vars { + out += ", " + item + } + out += ")\n\t\t\t\t\treturn" + } out += "\n\t\t\t}" } @@ -137,7 +155,7 @@ func (router *GenRouter) ServeHTTP(w http.ResponseWriter, req *http.Request) { NotFound(w,req) } ` - write_file("../gen_router.go",fdata) + write_file("./gen_router.go",fdata) fmt.Println("Successfully generated the router") } diff --git a/router_gen/routes.go b/router_gen/routes.go index fe5489c9..b5c20e22 100644 --- a/router_gen/routes.go +++ b/router_gen/routes.go @@ -33,4 +33,15 @@ func routes() { Route{"route_topics","/topics/","",[]string{}}, Route{"route_topic_create","/topics/create/","",[]string{"extra_data"}}, ) + + // The Control Panel + addRouteGroup("/panel/", + Route{"route_panel","/panel/","",[]string{}}, + Route{"route_panel_forums","/panel/forums/","",[]string{}}, + Route{"route_panel_forums_create_submit","/panel/forums/create/","",[]string{}}, + Route{"route_panel_forums_delete","/panel/forums/delete/","",[]string{"extra_data"}}, + Route{"route_panel_forums_delete_submit","/panel/forums/delete/submit/","",[]string{"extra_data"}}, + Route{"route_panel_forums_edit","/panel/forums/edit/","",[]string{"extra_data"}}, + Route{"route_panel_forums_edit_submit","/panel/forums/edit/submit/","",[]string{"extra_data"}}, + ) } diff --git a/run.bat b/run.bat index 17fb6881..2f93c96e 100644 --- a/run.bat +++ b/run.bat @@ -6,6 +6,16 @@ if %errorlevel% neq 0 ( exit /b %errorlevel% ) + +echo Building the router generator +go build ./router_gen +if %errorlevel% neq 0 ( + pause + exit /b %errorlevel% +) +echo Running the router generator +router_gen.exe + echo Building the executable go build -o gosora.exe if %errorlevel% neq 0 (