Example #1
0
func setupRoutes(r martini.Router) {
	// static
	r.Get("/", func(r render.Render) {
		r.HTML(http.StatusOK, "index", View("Dashboard"))
	})
	r.NotFound(func(r render.Render) {
		r.HTML(http.StatusNotFound, "404", View("404 - Not Found"))
	})

	// api
	r.Get("/api/hostname", DataHandler("hostname"))
	r.Get("/api/ip", DataHandler("ip"))
	r.Get("/api/cpu", DataHandler("cpu"))
	r.Get("/api/mem", DataHandler("mem"))
	r.Get("/api/disk", DataHandler("disk"))
	r.Get("/api/processes", DataHandler("top"))
	r.Get("/api/logged_on", DataHandler("logged_on"))
	r.Get("/api/users", DataHandler("passwd"))
	r.Get("/api/network", DataHandler("network"))
	r.Get("/api/env", DataHandler("env"))
	r.Get("/api/headers", DataHandler("headers"))

	r.Get("/api/debug/:method", DebugHandler)
}
Example #2
0
func configureRoutes(router martini.Router) {
	// 404 handler
	router.NotFound(func(render render.Render) {
		render.Redirect("/404")
	})

	// Common Routes
	router.Get("/", controllers.Home)
	router.Get("/404", controllers.NotFound)
	router.Get("/500", controllers.InternalServerError)

	// Player Routes
	router.Get("/players", controllers.GetPlayers)
	router.Get("/player/new", controllers.GetNewPlayer)
	router.Post("/player/new", binding.Form(controllers.PlayerData{}), controllers.CreatePlayer)
	router.Get("/player/:id", controllers.GetPlayerById)
	router.Post("/player/:id", binding.Form(controllers.PlayerData{}), binding.Form(controllers.OriginalData{}), controllers.ModifyPlayer)

	// Game Routes
	router.Get("/games", controllers.GetGames)
	router.Get("/game/new", controllers.GetNewGame)
	router.Post("/game/new", binding.Form(controllers.GameData{}), controllers.CreateGame)
	router.Get("/game/:id", controllers.GetGameById)
}
Example #3
0
// BindRoutes binds API routes.
func BindRoutes(r martini.Router) {

	r.NotFound(func(req *http.Request, r render.Render) {
		r.JSON(http.StatusNotFound, []string{"The requested url does not exists."})
	})

	r.Get("/api/status", Status)

	// Registration
	r.Group("/api", func(r martini.Router) {
		r.Group("/accounts", func(r martini.Router) {
			r.Post("/register", binding.Bind(accounts.RegisterViewModel{}), NotificatorHandler(), accounts.Register)
		})
	}, GatekeeperRouteHandler())

	// DASHBOARD GATEKEEPER
	r.Group("/api", func(r martini.Router) {
		r.Group("/auth", func(r martini.Router) {
			r.Post("/password", binding.Bind(auth.PasswordRequest{}), auth.Password)
		})
	}, GatekeeperRouteHandler(), AccountScopeHandler(), RepositoryScopeHandler())

	//ADMIN
	r.Group("/api", func(r martini.Router) {
		r.Get("/accounts", accounts.Index)
		r.Post("/accounts", binding.Bind(accounts.AccountViewModel{}), accounts.Post)
		r.Delete("/:id", accounts.Delete)
	}, AdminRouteHandler())

	//Owner / Manager
	r.Group("/api", func(r martini.Router) {
		r.Group("/accounts", func(r martini.Router) {
			r.Get("/:id", accounts.Get)
			r.Put("/:id", binding.Bind(accounts.AccountViewModel{}), accounts.Put)
		})

		r.Get("/devices", devices.Index)
		r.Post("/devices", binding.Bind(devices.DeviceViewModel{}), devices.Post)
		r.Group("/devices", func(r martini.Router) {
			r.Get("/:id", devices.Get)
			r.Put("/:id", binding.Bind(devices.DeviceViewModel{}), devices.Put)
			r.Post("/register", binding.Bind(devices.DeviceViewModel{}), devices.Post)
			r.Delete("/:id", devices.Delete)
		})

		r.Get("/doors", doors.Index)
		r.Post("/doors", binding.Bind(doors.DoorViewModel{}), doors.Post)
		r.Group("/doors", func(r martini.Router) {
			r.Get("/:id", doors.Get)
			r.Put("/:id", binding.Bind(doors.DoorViewModel{}), doors.Put)
			r.Delete("/:id", doors.Delete)
		})

		r.Post("/people", binding.Bind(people.PersonViewModel{}), people.Post)
		r.Group("/people", func(r martini.Router) {
			r.Post("/sync", BridgeHandler(), people.Sync)
			r.Delete("/:id", people.Delete)
		})

	}, AccountScopeHandler(), RepositoryScopeHandler(), SecuredRouteHandler(), ManagerRestrictedRouteHandler())

	//Account
	r.Group("/api", func(r martini.Router) {
		r.Group("/accounts", func(r martini.Router) {
			r.Get("/:id", accounts.Get)
		})

		r.Post("/notifications", NotificatorHandler(), binding.Bind(notifications.ViewModel{}), notifications.Notify)

		r.Get("/people", people.Index)
		r.Group("/people", func(r martini.Router) {
			r.Get("/:id", people.Get)
			r.Put("/:id", binding.Bind(people.PersonViewModel{}), people.Put)
		})

	}, AccountScopeHandler(), RepositoryScopeHandler(), SecuredRouteHandler())
}