1
0

routes.go 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. package http
  2. import (
  3. "net/http"
  4. "github.com/710leo/urlooker/modules/web/http/routes"
  5. "github.com/gorilla/mux"
  6. )
  7. func ConfigRouter(r *mux.Router) {
  8. configStraRoutes(r)
  9. configStaticRoutes(r)
  10. configApiRoutes(r)
  11. configDomainRoutes(r)
  12. configAuthRoutes(r)
  13. configUserRoutes(r)
  14. configTeamRoutes(r)
  15. configProcRoutes(r)
  16. }
  17. func configDomainRoutes(r *mux.Router) {
  18. r.HandleFunc("/url", routes.UrlStatus).Methods("GET")
  19. }
  20. func configChartRoutes(r *mux.Router) {
  21. r.HandleFunc("/chart", routes.UrlStatus).Methods("GET")
  22. }
  23. func configApiRoutes(r *mux.Router) {
  24. r.HandleFunc("/api/item/{idc}", routes.GetDetectItem).Methods("GET")
  25. }
  26. func configStraRoutes(r *mux.Router) {
  27. r.HandleFunc("/", routes.HomeIndex).Methods("GET")
  28. r.HandleFunc("/strategy/add", routes.AddStrategyGet).Methods("GET")
  29. r.HandleFunc("/strategy/add", routes.AddStrategyPost).Methods("POST")
  30. r.HandleFunc("/strategy/{id:[0-9]+}", routes.GetStrategyById).Methods("POST")
  31. r.HandleFunc("/strategy/{id:[0-9]+}/delete", routes.DeleteStrategy).Methods("POST")
  32. r.HandleFunc("/strategy/{id:[0-9]+}/edit", routes.UpdateStrategyGet).Methods("GET")
  33. r.HandleFunc("/strategy/{id:[0-9]+}/edit", routes.UpdateStrategy).Methods("POST")
  34. r.HandleFunc("/strategy/{id:[0-9]+}/teams", routes.GetTeamsOfStrategy).Methods("GET")
  35. }
  36. func configAuthRoutes(r *mux.Router) {
  37. r.HandleFunc("/auth/register", routes.RegisterPage).Methods("GET")
  38. r.HandleFunc("/auth/register", routes.Register).Methods("POST")
  39. r.HandleFunc("/auth/logout", routes.Logout).Methods("GET")
  40. r.HandleFunc("/auth/login", routes.Login).Methods("POST")
  41. r.HandleFunc("/auth/login", routes.LoginPage).Methods("GET")
  42. }
  43. func configUserRoutes(r *mux.Router) {
  44. r.HandleFunc("/me.json", routes.MeJson).Methods("GET")
  45. r.HandleFunc("/me/profile", routes.UpdateMyProfile).Methods("POST")
  46. r.HandleFunc("/me/chpwd", routes.ChangeMyPasswd).Methods("POST")
  47. r.HandleFunc("/users/query", routes.UsersJson).Methods("GET")
  48. }
  49. func configTeamRoutes(r *mux.Router) {
  50. r.HandleFunc("/teams", routes.TeamsPage).Methods("GET")
  51. r.HandleFunc("/teams/query", routes.TeamsJson).Methods("GET")
  52. r.HandleFunc("/team/create", routes.CreateTeamGet).Methods("GET")
  53. r.HandleFunc("/team/create", routes.CreateTeamPost).Methods("POST")
  54. r.HandleFunc("/team/{tid:[0-9]+}/edit", routes.UpdateTeamGet).Methods("GET")
  55. r.HandleFunc("/team/{tid:[0-9]+}/edit", routes.UpdateTeamPost).Methods("POST")
  56. r.HandleFunc("/team/{tid:[0-9]+}/users", routes.GetUsersOfTeam).Methods("GET")
  57. }
  58. func configProcRoutes(r *mux.Router) {
  59. //r.HandleFunc("/log", routes.GetLog).Methods("GET")
  60. r.HandleFunc("/version", routes.Version).Methods("GET")
  61. r.HandleFunc("/post_test", routes.Health).Methods("POST")
  62. r.HandleFunc("/put_test", routes.Health).Methods("PUT")
  63. }
  64. func configStaticRoutes(r *mux.Router) {
  65. r.PathPrefix("/css").Handler(http.FileServer(http.Dir("./modules/web/static")))
  66. r.PathPrefix("/fonts").Handler(http.FileServer(http.Dir("./modules/web/static")))
  67. r.PathPrefix("/js").Handler(http.FileServer(http.Dir("./modules/web/static")))
  68. r.PathPrefix("/img").Handler(http.FileServer(http.Dir("./modules/web/static")))
  69. r.PathPrefix("/lib").Handler(http.FileServer(http.Dir("./modules/web/static")))
  70. }