func Mount(m *martini.ClassicMartini, concurrent int) { fmt.Println("concurrent @v:", concurrent) m.Use(utee.MidConcurrent(concurrent)) m.Use(render.Renderer()) m.Use(utee.MidTextDefault) // //map request web utilities m.Use(func(w http.ResponseWriter, c martini.Context) { web := &utee.Web{W: w} c.Map(web) }) m.Use(func(c martini.Context){ var msgs []string for i:=0;i<100000;i++ { msgs = append(msgs,fmt.Sprint("testMsg",i)) } c.Map(msgs) }) m.Group("/hello", func(r martini.Router) { r.Post("/world", test) r.Get("/world", test) }) http.Handle("/", m) // http.HandleFunc("/test/a", testhandler) }
func InitRouters(m *martini.ClassicMartini) { //Routers for front pages m.Get("/", HandleIndex) m.Get("/tips/:Id", HandleTip) m.Get("/random_tips/txt", HandleRandomTxtTip) m.Get("/random_tips/json", HandleRandomJsonTip) m.Get("/casts", paginate.Handler, HandleCasts) m.Get("/casts/:Id", ShowCast) m.Get("/api", HandleAPI) m.Get("/tools", HandleTools) m.Get("/about", HandleAbout) m.Get("/admin/login", ShowLoginPage) m.Get("/admin/logout", HandleLogout) m.Post("/admin/login", HandleLogin) //Routers for admin panel m.Group("/admin", func(r martini.Router) { r.Get("/index", HandleAdminIndex) r.Get("/tips", paginate.Handler, AdminShowTips) r.Post("/tips/add", AdminAddTips) r.Post("/tips/del", AdminDelTips) r.Post("/tips/update", AdminModifyTips) r.Get("/casts", paginate.Handler, AdminShowCasts) r.Get("/password", AdminPassword) r.Post("/password", AdminUpdatePassword) r.Get("/casts/add", AdminAddCastsPage) r.Post("/casts", AdminAddCasts) r.Post("/casts/del", AdminDelCasts) r.Post("/casts/modify", AdminUpdateCasts) r.Get("/casts/modify/:Id", AdminModifyCasts) }, validateSession) }
//InitRoutes - initialize the mappings for controllers against valid routes func InitRoutes(m *martini.ClassicMartini, redisConn Doer, mongoConn pezdispenser.MongoCollectionGetter, authClient AuthRequestCreator) { setOauthConfig() keyGen := NewKeyGen(redisConn, &GUIDMake{}) m.Use(render.Renderer()) m.Use(martini.Static(StaticPath)) m.Use(oauth2.Google(OauthConfig)) authKey := NewAuthKeyV1(keyGen) m.Get("/info", authKey.Get()) m.Get(ValidKeyCheck, NewValidateV1(keyGen).Get()) m.Get("/me", oauth2.LoginRequired, DomainCheck, NewMeController().Get()) m.Get("/", oauth2.LoginRequired, DomainCheck, func(params martini.Params, log *log.Logger, r render.Render, tokens oauth2.Tokens) { userInfo := GetUserInfo(tokens) r.HTML(SuccessStatus, "index", userInfo) }) m.Post("/sandbox", oauth2.LoginRequired, DomainCheck, NewSandBoxController().Post()) m.Group(URLAuthBaseV1, func(r martini.Router) { r.Put(APIKey, authKey.Put()) r.Get(APIKey, authKey.Get()) r.Delete(APIKey, authKey.Delete()) }, oauth2.LoginRequired, DomainCheck) m.Group(URLOrgBaseV1, func(r martini.Router) { pcfOrg := NewOrgController(mongoConn, authClient) r.Put(OrgUser, pcfOrg.Put()) r.Get(OrgUser, pcfOrg.Get()) }, oauth2.LoginRequired, DomainCheck) }
//controller转发规则设置 func controller(m *martini.ClassicMartini) { // {{{ m.Get("/", func(r render.Render) { r.HTML(200, "index", nil) }) m.Group("/schedules", func(r martini.Router) { //Schedule部分 r.Get("", GetSchedules) r.Post("", binding.Bind(schedule.Schedule{}), AddSchedule) r.Get("/:id", GetScheduleById) r.Put("/:id", binding.Bind(schedule.Schedule{}), UpdateSchedule) r.Delete("/:id", DeleteSchedule) //Job部分 r.Get("/:sid/jobs", GetJobsForSchedule) r.Post("/:sid/jobs", binding.Bind(schedule.Job{}), AddJob) r.Put("/:sid/jobs/:id", binding.Bind(schedule.Job{}), UpdateJob) r.Delete("/:sid/jobs/:id", DeleteJob) //Task部分 r.Post("/:sid/jobs/:jid/tasks", binding.Bind(schedule.Task{}), AddTask) r.Put("/:sid/jobs/:jid/tasks/:id", binding.Bind(schedule.Task{}), UpdateTask) r.Delete("/:sid/jobs/:jid/tasks/:id", DeleteTask) //TaskRelation部分 r.Post("/:sid/jobs/:jid/tasks/:id/reltask/:relid", AddRelTask) r.Delete("/:sid/jobs/:jid/tasks/:id/reltask/:relid", DeleteRelTask) }) } // }}}
func RouterSiginInit(m *martini.ClassicMartini) { m.Group("/sign", func(r martini.Router) { r.Get("/in", SignIn) r.Post("/in/todo", SignInTodo) r.Get("/up", SignUp) r.Post("/up/todo", SignUpTodo) }) }
func RouterUserInit(m *martini.ClassicMartini) { m.Group("/user", func(r martini.Router) { r.Get("/list", ListUser) r.Get("/upd/:id", UpdUser) r.Post("/upd/todo", UpdUserTodo) r.Get("/del/:id", DelUser) }, middlewares.Auth()) }
func SetupRoutes(db *mgo.Database, m *martini.ClassicMartini) { m.Group("/oauth", func(r martini.Router) { r.Get("/register/:type", modules.Register) r.Get("/github", binding.Bind(models.GithubOAuth{}), modules.GithubOAuth) }) m.Group("/api/user", func(r martini.Router) { r.Put("/", binding.Bind(models.User{}), api.RegisterUser) }) }
func RoutePage(m *martini.ClassicMartini) { m.Group("/appmanager", func(r martini.Router) { r.Get("", page_index) r.Get("/channel/list", page_channel_list) r.Get("/version/add", page_version_add) r.Get("/channel/add", page_channel_add) r.Post("/version/add", version_add) r.Post("/channel/add/submit", binding.Bind(ChannelAddForm{}), channel_add) }) }
func setupUsersCtrl(app *martini.ClassicMartini) { app.Group("/users", func(r martini.Router) { app.Get("", usersIndexAction) app.Get("/add", usersAddAction) app.Post("", sessions.RequireCsrfToken, usersCreateAction) app.Get("/:id", usersEditAction) app.Put("/:id", sessions.RequireCsrfToken, usersUpdateAction) app.Delete("/:id", sessions.RequireCsrfToken, usersDeleteAction) app.Get("/:id/delete", usersDeleteConfirmAction) }, sessions.RequireLogin) }
func mapRoutes(server *martini.ClassicMartini) { server.Get("/", controller.Home) server.Group("/api", func(apiRoutes martini.Router) { apiRoutes.Get("/pages", api.PageIndex) apiRoutes.Get("/pages/:id", api.PageShow) apiRoutes.Group("/pages/:pageId", func(pageRoutes martini.Router) { pageRoutes.Get("/posts", api.PostIndex) }) }) }
func setupConsumersCtrl(app *martini.ClassicMartini) { app.Group("/consumers", func(r martini.Router) { app.Get("", consumersIndexAction) app.Get("/add", consumersAddAction) app.Post("", sessions.RequireCsrfToken, consumersCreateAction) app.Get("/:id", consumersEditAction) app.Put("/:id", sessions.RequireCsrfToken, consumersUpdateAction) app.Delete("/:id", sessions.RequireCsrfToken, consumersDeleteAction) app.Get("/:id/delete", consumersDeleteConfirmAction) app.Get("/:id/urls", consumersUrlsAction) }, sessions.RequireLogin) // public app.Get("/info/:consumer/:token", consumerInfoAction) }
func InitRoutes(m *martini.ClassicMartini) { m.Group("/devices", func(r martini.Router) { r.Get("", ListDevices) r.Post("", binding.Form(models.Device{}), CreateDevice) r.Get("/new", NewDevice) // r.Get("/:id", ShowDevice) }) m.Get("/sock", Socket) m.Get("/node", Node) m.NotFound(func(r render.Render) { r.HTML(404, "status/404", "") }) }
func Configure(m *martini.ClassicMartini) { m.Group("/humidity", func(r martini.Router) { r.Post("", humidity.Post) r.Get("", humidity.Get) }) m.Get("/current/humidity", current_humidity.Get) m.Group("/", func(r martini.Router) { r.Get("", index.Get) }) static := martini.Static("templates", martini.StaticOptions{Fallback: "/index.tmpl", Exclude: "/api/v"}) m.NotFound(static, http.NotFound) m.Use(martini.Static("static")) }
func Register(m *martini.ClassicMartini) { m.Get("/ruok", Ruok) m.Any("/", Home) m.Any("/doc", Doc) m.Any("/repo", Repo) m.Any("/history", History) m.Any("/download", Download) m.Post("/new-repo", binding.Bind(RepoInfoForm{}), NewRepo) m.Any("/search", Search) m.Group("/api", func(r martini.Router) { m.Get("/pkglist", PkgList) m.Post("/build", binding.Bind(RepositoryForm{}), NewBuild) m.Post("/force-rebuild", binding.Bind(TaskForm{}), ForceRebuild) }) m.Get("/badge/**", Badge) m.Get("/**", Repo) // for the rest of request // Not found handler. // m.NotFound(routers.NotFound) }
//InitRoutes - initialize the mappings for controllers against valid routes func InitRoutes(m *martini.ClassicMartini, validationTargetUrl string) { keyCheckHandler := keycheck.NewAPIKeyCheckMiddleware(validationTargetUrl).Handler() itemLeaseController := NewLeaseController(APIVersion1, Item) typeLeaseController := NewLeaseController(APIVersion1, Type) listLeaseController := NewLeaseController(APIVersion1, List) lockController := NewLockController(APIVersion1) m.Group("/", func(r martini.Router) { r.Get("info", func() string { return "the dispenser service will give you candy" }) }) m.Group(URLLeaseBaseV1, func(r martini.Router) { r.Post(URLTypeGUID, typeLeaseController.Post()) r.Get(URLTypeGUID, typeLeaseController.Get()) r.Post(URLItemGUID, itemLeaseController.Post()) r.Get(URLItemGUID, itemLeaseController.Get()) r.Delete(URLItemGUID, itemLeaseController.Delete()) r.Get(URLLeases, listLeaseController.Get()) }, keyCheckHandler) m.Group(URLLockBaseV1, func(r martini.Router) { r.Post(URLItemGUID, lockController.Post()) r.Get(URLItemGUID, lockController.Get()) }, keyCheckHandler) }
func RouteApi(m *martini.ClassicMartini) { m.Group("/api", func(r martini.Router) { r.Get("/app", api_app_list) r.Post("/app", binding.Json(App{}), api_app_post) r.Get("/app/:id", api_app_get) r.Put("/app/:id", api_app_put) r.Delete("/app/:id", api_app_delete) r.Get("/app/:appid/version", api_version_list) r.Post("/app/:appid/version", binding.Json(Version{}), api_version_post) r.Get("/app/:appid/version/:id", api_version_get) r.Put("/app/:appid/version/:id", api_version_put) r.Delete("/app/:appid/version/:id", api_version_delete) r.Get("/app/:appid/channel", api_channel_list) r.Post("/app/:appid/channel", binding.Json(Channel{}), api_channel_post) r.Get("/app/:appid/channel/:id", api_channel_get) r.Put("/app/:appid/channel/:id", api_channel_put) r.Delete("/app/:appid/channel/:id", api_channel_delete) r.Post("/build", api_app_build) r.Get("/build/tasks", api_app_build_tasks) }) }
// RegisterTeamsResource build and register the teams resource handler using the given database and martini instance. func RegisterTeamsResource(resourceName string, api *martini.ClassicMartini, database *mgo.Database) { // Get a handle to the collection needed for this resource. collection := database.C(resourceName) baseURI := fmt.Sprintf("/%s", resourceName) // Ensure needed indices. ensureTeamsIndices(collection) // Bind the users resource group. api.Group(baseURI, func(router martini.Router) { // Handle POST requests. router.Post("/", binding.Bind(Team{}), func(team Team) string { // Create the new team. persistedTeam := createTeam(team, collection) // Marshall team to JSON and cast to string for API repr. output, err := json.Marshal(persistedTeam) if err != nil { panic(err) } return string(output) }) // Handle DELETE requests. router.Delete("/:id", func(params martini.Params) string { id := bson.ObjectIdHex(params["id"]) if err := collection.RemoveId(id); err != nil { log.Fatal(err) panic(err) } return params["id"] }) }) }
func (ctn *Routes) SetRouter(m *martini.ClassicMartini) { m.Get("/", func(rend render.Render) { rend.HTML(200, "index", nil) }) m.Get("/socket", sockets.JSON(webSocket.Message{}), ctrlWebSocket.Socket) m.Group("/aj/client", func(r martini.Router) { r.Get("/list", client.List) r.Get("/:id/backuplist", client.GetBackupList) r.Get("/:id/log", client.ShowLog) r.Get("/:id/unDeploy", client.GetUnDeployFiles) r.Post("/check", client.Check) r.Post("/add", client.Add) r.Post("/refresh", client.Refresh) r.Post("/:id/edit", client.Edit) r.Post("/:id/del", client.Del) r.Post("/:id/change/group/:gid", client.Move) r.Post("/:id/update", client.Update) r.Post("/:id/deploy", client.Deploy) r.Post("/:id/revert", client.Revert) r.Post("/:id/removebackup", client.RemoveBackup) }) m.Group("/aj/group", func(r martini.Router) { r.Post("/add", group.Add) }) m.Group("/aj", func(r martini.Router) { r.Get("/error", master.ShowError) r.Get("/lastVersion", master.GetLastVersion) r.Post("/update", master.Update) r.Post("/compile", master.Compile) }) m.Group("/aj/config", func(r martini.Router) { r.Get("/aj/config/add", config.Add) }) }
func setupAccessLogCtrl(app *martini.ClassicMartini) { app.Group("/accesslog", func(r martini.Router) { app.Get("", accessLogIndexAction) }, sessions.RequireLogin) }
// RegisterUsersResource build and register the users resource handler using the given database and martini instance. func RegisterUsersResource(resourceName string, api *martini.ClassicMartini, database *mgo.Database) { // Get a handle to the collection needed for this resource. collection := database.C(resourceName) baseURI := fmt.Sprintf("/%s", resourceName) // Ensure needed indices. ensureUsersIndices(collection) // Bind the users resource group. api.Group(baseURI, func(router martini.Router) { // Handle GET requests for objects by ID. router.Get("/:id", func(params martini.Params) (int, string) { // Ensure the ID is valid, else 400. idString := params["id"] if !bson.IsObjectIdHex(idString) { errorMessage := fmt.Sprintf("Invalid user ID: '%s'.", idString) apiError := common.APIError{Error: errorMessage} apiErrorJSON, err := json.Marshal(apiError) if err != nil { log.Fatal(err) panic(err) } return 400, string(apiErrorJSON) } // Fetch the user specified by ID. id := bson.ObjectIdHex(params["id"]) user := User{} if err := collection.FindId(id).One(&user); err != nil { log.Fatal(err) panic(err) } // Marshall user to JSON and cast to string for API repr. output, err := json.Marshal(user) if err != nil { log.Fatal(err) panic(err) } return 200, string(output) }) // Handle POST requests. router.Post("/", binding.Bind(User{}), func(user User) string { // Create the new user. persistedUser := createUser(user, collection) // Marshall user to JSON and cast to string for API repr. output, err := json.Marshal(persistedUser) if err != nil { panic(err) } return string(output) }) // Handle DELETE requests. router.Delete("/:id", func(params martini.Params) string { id := bson.ObjectIdHex(params["id"]) if err := collection.RemoveId(id); err != nil { log.Fatal(err) panic(err) } return params["id"] }) }) }