func addStaffRoutes(r martini.Router) { r.Group("/staff", func(r martini.Router) { r.Get("", func() string { return "Staff stuff?" }) }, ensureStaffMember) }
func EnsureAuth(r martini.Router, mainDb *d.MainDb) martini.Router { r.Get("/", func(r render.Render, prms martini.Params, req *http.Request) { flashMessage, fType := flash.GetMessage() query := req.URL.Query() result := map[string]interface{}{ fmt.Sprintf("flash_%v", fType): flashMessage, "from": query.Get("from"), } r.HTML(200, "login", AddCurrentUser(result, req, mainDb), render.HTMLOptions{Layout: "base"}) }) r.Post("/", binding.Bind(user{}), func(postedUser user, r render.Render, req *http.Request, w http.ResponseWriter) { userData, err := mainDb.Users.LoginUser(postedUser.LoginName, postedUser.Password) if err != nil { log.Printf("AUTH user %+v not found: %v", postedUser, err) flash.SetMessage("К сожалению, пользователь с такими данными не найден.", "error") r.Redirect(AUTH_URL) return } else { log.Printf("AUTH found user data: %v, %v, %v", userData.UserId, userData.UserName, userData.Auth) } user := NewUser(userData) StartAuthSession(user, w) redirect := req.URL.Query().Get(REDIRECT_PARAM) if redirect == "" { redirect = DefaultUrlMap.GetDefaultUrl(user.BelongsToCompany()) } http.Redirect(w, req, redirect, 302) }) return r }
// mapChildNamespaceRoute sets a handler returning a dictionary of resources // supported by a certain API version identified by the given namespace func mapChildNamespaceRoute(route martini.Router, namespace *schema.Namespace) { log.Debug("[Path] %s", namespace.GetFullPrefix()) route.Get( namespace.GetFullPrefix(), func(w http.ResponseWriter, r *http.Request, p martini.Params, context martini.Context) { resources := []schema.NamespaceResource{} for _, s := range schema.GetManager().Schemas() { if s.NamespaceID == namespace.ID { resources = append(resources, schema.NamespaceResource{ Links: []schema.Link{ schema.Link{ Href: s.GetPluralURL(), Rel: "self", }, }, Name: s.Singular, Collection: s.Plural, }) } } routes.ServeJson(w, map[string][]schema.NamespaceResource{"resources": resources}) }, ) }
// mapTopLevelNamespaceRoute maps route listing available subnamespaces (versions) // for a top-level namespace func mapTopLevelNamespaceRoute(route martini.Router, namespace *schema.Namespace) { log.Debug("[Path] %s/", namespace.GetFullPrefix()) route.Get( namespace.GetFullPrefix()+"/", func(w http.ResponseWriter, r *http.Request, p martini.Params, context martini.Context) { versions := []schema.Version{} for _, childNamespace := range schema.GetManager().Namespaces() { if childNamespace.Parent == namespace.ID { versions = append(versions, schema.Version{ Status: "SUPPORTED", ID: childNamespace.Prefix, Links: []schema.Link{ schema.Link{ Href: childNamespace.GetFullPrefix() + "/", Rel: "self", }, }, }) } } if len(versions) != 0 { versions[len(versions)-1].Status = "CURRENT" } routes.ServeJson(w, map[string][]schema.Version{"versions": versions}) }) }
func (tr *TaskRouter) Register(r martini.Router) { r.Get("", tr.GetAllTasks) r.Post("", tr.CreateTask) r.Get("/:id", tr.GetTask) r.Put("/:id", tr.CreateTask) r.Delete("/:id", tr.CancelTask) }
func CreateJobsRoutes(r martini.Router) { jobrunner.Start() // optional: jobrunner.Start(pool int, concurrent int) (10, 1) jobrunner.Schedule("@every 5s", ReminderEmails{}) jobrunner.Schedule("@every 10s", ReminderEmails{}) entries := jobrunner.Entries() fmt.Println(entries[len(entries)-1].ID) r.Get("/status", requestJobs) }
func setup(router martini.Router) { router.Get("/user/:id", controllers.UserGet) router.Put("/user/:id", binding.Json(models.User{}), binding.ErrorHandler, controllers.UserPut) }
func (lr *SiteRouter) Register(r martini.Router) { r.Get("", lr.GetAll) r.Get("/:id", lr.GetSite) r.Put("/:id", lr.PutSite) r.Delete("/:id", lr.DeleteSite) }
func initCurrencyApi(r martini.Router) { r.Group("/currencies", func(r martini.Router) { r.Get("", func() string { var _, body, _ = request.Get("http://api.fixer.io/latest?base=USD").End() return body }) }) }
func (lr *ThingRouter) Register(r martini.Router) { r.Get("", lr.GetAll) r.Get("/:id", lr.GetThing) r.Put("/:id", lr.PutThing) r.Put("/:id/location", lr.PutThingLocation) r.Delete("/:id", lr.DeleteThing) }
func (lr *LocationRouter) Register(r martini.Router) { r.Get("/calibration/scores", lr.GetCalibrateScores) r.Get("/calibration/device", lr.GetCalibrateDevice) r.Get("/calibration/progress", lr.GetCalibrationProgress) r.Post("/thing", lr.PostCreateThing) }
func addResourceRoutes(r martini.Router) { r.Get("/resources", func() string { return "All my resources" }) r.Get("/resources/:id", func(p martini.Params) string { return "Resources(" + p["id"] + ")" }) }
func addNeedRoutes(r martini.Router) { r.Group("/needs", func(r martini.Router) { r.Get("", func() string { return "All my needs" }) r.Get("/:id", func(p martini.Params) string { return "Need(" + p["id"] + ")" }) }) }
func (lr *RoomRouter) Register(r martini.Router) { r.Get("", lr.GetAll) r.Post("", lr.PostNewRoom) r.Get("/:id", lr.GetRoom) r.Delete("/:id", lr.DeleteRoom) r.Put("/:id", lr.UpdateRoom) // r.Get("/:id/things", lr.GetThings) Not sure if this was used r.Put("/:id/calibrate", lr.PutCalibrateRoom) r.Put("/:id/apps/:appName", lr.PutAppRoomMessage) }
func (us UserService) Register(router martini.Router) { utils.Log.Debug("Registering UserService!") router.Group("/users", func(rtr martini.Router) { rtr.Post("", PreventReauth, binding.Bind(models.User{}), us.Create) rtr.Post("/update", EnsureAuth, binding.Bind(models.User{}), us.Update) }) router.Get("/signout", us.SignOut) router.Get("/signup", PreventReauth, us.SignUp) router.Get("/signin", PreventReauth, us.SignIn) router.Get("/dashboard", EnsureAuth, us.Dashboard) router.Get("/settings/edit", EnsureAuth, us.Edit) router.Get("/settings/edit/:category", EnsureAuth, us.Edit) router.Get("/wakatime/sync", EnsureAuth, us.SyncHeartbeats) }
func attachAPI(api martini.Router) { api.Get("/user", getCurrentUser) api.Get("/users", getUsers) api.Post("/users", newUser) api.Get("/users/:name", getUser) //api.Put("/users/:name", updateUser) api.Get("/users/:name/projects", getProjects) //api.Post("/users/:name/projects", newProject) //apiGets.HandleFunc("/projects", getProjects) }
// AdminRoute manages routing for Restful API func AdminRoute(r martini.Router) { r.Get("/rest/metadata", AdminGetModels) r.Get("/rest/metadata/:modelName", AdminGetMetaData) r.Group("/rest/:modelName", func(restRoutes martini.Router) { restRoutes.Get("", AdminGetList) restRoutes.Get("/:id", AdminGetEntity) restRoutes.Post("", AdminNewEntity) restRoutes.Put("/:id", AdminUpdateEntity) restRoutes.Delete("/:id", AdminDeleteEntity) }) r.Get("/", AdminIndex) }
func SetupCommentRoutes(r martini.Router) { r.Get("/comments", ListComments) r.Get("/todo/:id/comments", ListCommentsByTodo) r.Post("/comments", binding.Json(Comment{}), CreateComment) }
func initBooksApi(r martini.Router) { r.Group("/books", func(r martini.Router) { r.Get("", getBooks) }) }
func RegisterRoutes(r martini.Router) { r.Get("/debug/pprof/cmdline", pprof.Cmdline) r.Get("/debug/pprof/profile", pprof.Profile) r.Get("/debug/pprof/symbol", pprof.Symbol) r.Get("/debug/pprof/**", pprof.Index) }
func MockRouter(r martini.Router) { r.Get("/**", GetMock) r.Post("/**", GetMock) }
func (this *EurekaRequestGet) SetRoutes(r martini.Router) { r.Get("/apps", this.requestApplications) r.Get("/apps/:appId", this.requestApplication) r.Get("/apps/:appId/:instanceId", this.requestInstance) }
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) }
func Routes(router martini.Router) { router.Get("/", IndexAction).Name("/api") router.Get("/welcome/(?P<name>[a-zA-Z]+)", WelcomeAction).Name("/api/welcome") }
// 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()) }
func userRouter(r martini.Router) { r.Get("/one", one) r.Get("/two", two) }
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) }
func SetupTodoRoutes(r martini.Router) { r.Get("/todos", ListTodos) r.Post("/todos", binding.Json(Todo{}), CreateTodo) r.Put("/todos", binding.Json(Todo{}), UpdateTodo) }
func PresetRouter(r martini.Router) { r.Get("/", GetPreset) r.Post("/", CreatePreset) }
func Namespaces(r martini.Router) { r.Get("/", all) r.Get("/:name", namespace) }