func prepareRoutes(router *gin.Engine) { // Web Resources router.Static("/static", "web/dist") // API Routes api := router.Group("/api/v1") admin := api.Group("/admin") public := api.Group("/public") registered := api.Group("/") sameRegisteredUser := api.Group("/user") prepareMiddleware(admin, public, registered, sameRegisteredUser) admin.GET("/users", listUsers) admin.GET("/places", listPlaces) admin.POST("/places", createPlace) admin.POST("/events", createEvent) admin.PUT("/place/:placeId", updatePlace) admin.PUT("/event/:eventId", updateEvent) admin.DELETE("/event/:eventId", cancelEvent) sameRegisteredUser.GET("/:userId", getUser) sameRegisteredUser.PUT("/:userId", updateUser) sameRegisteredUser.DELETE("/:userId", disableUser) registered.POST("/buy/:seatId", buyTicket) public.GET("/place/:placeId", getPlace) public.GET("/events", listEvents) public.GET("/event/:eventId", getEvent) public.POST("/users", createUser) // TODO Checar, me huele raro...... public.POST("/login", loginUser) }
// SetRoutes sets the crud and migration (if them exists) routes func SetRoutes(r *gin.Engine) { taskRoute := r.Group("/api/task") taskRoute.Use(jwt.Auth(config.TokenSecret)) // Task CRUD taskRoute.GET("/*id", taskRetrieveRoute) taskRoute.POST("/", taskCreateRoute) taskRoute.PUT("/:id", taskUpdateRoute) taskRoute.DELETE("/:id", taskDeleteRoute) }
func registerRoutes(server *gin.Engine) { podRoute := server.Group("/pod") { podRoute.POST("/create", PodCreate) podRoute.GET("/state/:pod", PodState) } }
func mapRoutes(router *gin.Engine) { router.Use(cors.Middleware(cors.Config{ Origins: "http://openbonfires.github.io, https://openbonfires.github.io", })) //mapped router for authenticated urls only api := router.Group("/api") api.GET("/randomquote", func(c *gin.Context) { res, err := http.Get("http://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=en") if err == nil { defer res.Body.Close() body, err := ioutil.ReadAll(res.Body) if err == nil { c.String(http.StatusOK, string(body)) } else { c.String(http.StatusInternalServerError, "Unable to read the response date from the random quotes API.") } } else { c.String(http.StatusInternalServerError, "Unable to communicate with random quotes API.") } }) //All other requests router.Use(func(c *gin.Context) { c.String(http.StatusNotFound, "Requested url does not exist") c.Abort() }) }
func Init(router *gin.Engine, DB *db.Session, fn func() gin.HandlerFunc) { // Simple group: v1 api := &API{DB} v1 := router.Group("/v1") { v1.Use(fn()) policies := v1.Group("policies") { policies.POST("/", api.createPolicy) policies.GET("/", api.getPolicies) policies.DELETE("/", api.deletePolicies) policies.DELETE("/:id", api.deletePolicy) policies.PUT("/:id", api.updatePolicy) } res := v1.Group("resources") { res.POST("/", api.createResource) res.GET("/:type", api.getResources) //res.GET("/:type/:id", api.getResources) res.DELETE("/", api.deleteResources) res.DELETE("/:id", api.deleteResource) res.PUT("/:id", api.updateResource) } } }
func SetupRoutes(router *gin.Engine) { router.GET("/", GetHome) router.GET("/static/*path", GetAsset) api := router.Group("/api") { SetupMiddlewares(api) api.GET("/info", GetInfo) api.POST("/connect", Connect) api.GET("/databases", GetDatabases) api.GET("/connection", GetConnectionInfo) api.GET("/activity", GetActivity) api.GET("/schemas", GetSchemas) api.GET("/tables", GetTables) api.GET("/tables/:table", GetTable) api.GET("/tables/:table/rows", GetTableRows) api.GET("/tables/:table/info", GetTableInfo) api.GET("/tables/:table/indexes", GetTableIndexes) api.GET("/query", RunQuery) api.POST("/query", RunQuery) api.GET("/explain", ExplainQuery) api.POST("/explain", ExplainQuery) api.GET("/history", GetHistory) api.GET("/bookmarks", GetBookmarks) } }
// setupRoutes is an internal method where we setup application routes func setupRoutes(r *gin.Engine) { // TODO: home route "/" is not yet defined. // r.GET("/", ...) // static files served by application r.Static("/static", "./static") // auth urls for the login form and logout url r.GET("/login", auth.Login) r.POST("/login", auth.Login) r.GET("/logout", auth.Logout) // sessionResource is a special auth api resource, with POST and DELETE // endpoints used for logging a user in or out. sessionResource := r.Group("/api/session") { sessionResource.POST("", auth.LoginAPI) sessionResource.DELETE("", auth.LogoutAPI) } // admin urls adminRoutes := r.Group("/admin", auth.LoginRequired()) { adminRoutes.GET("", admin.Admin) adminRoutes.GET("/json", admin.JSONTest) } }
// InitRoutesTopics initialized routes for Topics Controller func InitRoutesTopics(router *gin.Engine) { topicsCtrl := &controllers.TopicsController{} g := router.Group("/") g.Use(CheckPassword()) { g.GET("/topics", topicsCtrl.List) g.POST("/topic", topicsCtrl.Create) g.DELETE("/topic/*topic", topicsCtrl.Delete) g.GET("/topic/*topic", topicsCtrl.OneTopic) g.PUT("/topic/add/parameter", topicsCtrl.AddParameter) g.PUT("/topic/remove/parameter", topicsCtrl.RemoveParameter) g.PUT("/topic/add/rouser", topicsCtrl.AddRoUser) g.PUT("/topic/remove/rouser", topicsCtrl.RemoveRoUser) g.PUT("/topic/add/rwuser", topicsCtrl.AddRwUser) g.PUT("/topic/remove/rwuser", topicsCtrl.RemoveRwUser) g.PUT("/topic/add/adminuser", topicsCtrl.AddAdminUser) g.PUT("/topic/remove/adminuser", topicsCtrl.RemoveAdminUser) g.PUT("/topic/add/rogroup", topicsCtrl.AddRoGroup) g.PUT("/topic/remove/rogroup", topicsCtrl.RemoveRoGroup) g.PUT("/topic/add/rwgroup", topicsCtrl.AddRwGroup) g.PUT("/topic/remove/rwgroup", topicsCtrl.RemoveRwGroup) g.PUT("/topic/add/admingroup", topicsCtrl.AddAdminGroup) g.PUT("/topic/remove/admingroup", topicsCtrl.RemoveAdminGroup) g.PUT("/topic/param", topicsCtrl.SetParam) } }
// Init initializes application routers. func Init(g *gin.Engine) { g.Use(middleware.UserFromToken()) // Home page. g.GET("/", Home) // Health check group. h := g.Group("/h") { h.GET("/ping", health.Ping) } // User related group. u := g.Group("/user") { usin := u.Group("/signin") usin.Use(middleware.NotAuthenticated()) { usin.POST("/:service", auth.SignIn) usin.GET("/:service/complete", auth.SignInComplete) } urepos := u.Group("/repos") urepos.Use(middleware.Authenticated()) { urepos.GET("/:service", repos.ReposList) urepos.PATCH("/:service", repos.ReposUpdate) } } }
// wire up the greetings routes func initGreetings(e *gin.Engine, f engine.EngineFactory, endpoint string) { greeter := &greeter{f.NewGreeter()} g := e.Group(endpoint) { g.GET("", greeter.list) g.POST("", greeter.add) } }
func (r *TurmaResource) register(router *gin.Engine) { grupo := router.Group("/ges/v1/api") grupo.GET("/turmas", r.obterTodas) grupo.POST("/turmas", r.cadastrar) grupo.PUT("/turmas/:id", r.alterar) grupo.DELETE("/turmas/:id", r.excluir) }
func Register(r *gin.Engine) { api(r.Group("/api")) r.GET("/", showIndex) r.GET("/h/:_", showIndex) r.GET("/p/:_", showIndex) }
func buildRoutes(r *gin.Engine) { v1 := r.Group("/v1") { v1.GET(encryptPath, encryptContext()) v1.POST(encryptPath, newEncryptContext()) v1.GET(decryptPath, decryptContext()) v1.GET(echoPath, echoContext()) } }
// Register registers the route handlers for this controller func (f *FrontController) Register(r *gin.Engine) { front := r.Group("/") { front.GET("/", f.getIndex) front.GET("/healthcheck", f.getHealthCheck) } r.NoRoute(f.getNotFound) }
func configApi(engine *gin.Engine) { api := engine.Group("/api") { api.GET("/", func(c *gin.Context) { c.Writer.WriteHeader(200) }) api.POST("/todos", NewTodo) api.GET("/todos", ListTodos) api.DELETE("/todos/:id", DeleteTodo) api.PUT("/todos/:id", UpateTodo) } }
func Init(router *gin.Engine, DB *db.Session) { // Simple group: login l := &Login{DB} loginRouter := router.Group("/login") { loginRouter.POST("/register", l.registerUser) loginRouter.POST("/authorize", l.loginUser) loginRouter.GET("/logout", l.logoutUser) loginRouter.DELETE("/remove", l.deleteSelf) } }
// InitRoutesPresences initialized routes for Presences Controller func InitRoutesPresences(router *gin.Engine) { presencesCtrl := &controllers.PresencesController{} g := router.Group("/") g.Use(CheckPassword()) { // List Presences g.GET("presences/*topic", presencesCtrl.List) // Add a presence and get list g.POST("presenceget/*topic", presencesCtrl.CreateAndGet) } }
func (r *gin.Engine) UseApi() error { eventsV1 := r.Group("/api/v1/events") { eventsV1.GET("/:eventId/:orderId/confirm", confirmOrder) eventsV1.GET("/:eventId/:orderId", getOrder) eventsV1.GET("/:eventId/:orderId/state", getState) eventsV1.POST("/:eventId/:orderId/billinginfo", updateBillingInfo) eventsV1.POST("/:eventId", createOrder) } return nil }
// RouteAPI contains router groups for API func RouteAPI(parentRoute *gin.Engine) { route := parentRoute.Group(config.APIURL) { v1.Users(route) v1.Roles(route) v1.Authentications(route) v1.Articles(route) v1.Locations(route) v1.Upload(route) v1.Experiments(route) v1.Oauth(route) } }
//Mount mount web func (p *Engine) Mount(r *gin.Engine) { rg := r.Group("/ops/mail", p.Jwt.MustRolesHandler("ops")) rg.GET("/domains", web.Rest(p.indexDomain)) rg.POST("/domains", web.Rest(p.createDomain)) rg.DELETE("/domains/:id", web.Rest(p.deleteDomain)) rg.GET("/users", web.Rest(p.indexUser)) rg.POST("/users", web.Rest(p.createUser)) rg.DELETE("/users/:id", web.Rest(p.deleteUser)) rg.GET("/aliases", web.Rest(p.indexAlias)) rg.POST("/aliases", web.Rest(p.createAlias)) rg.DELETE("/aliases/:id", web.Rest(p.deleteAlias)) }
/* New creares a new API instance with all routes configured */ func New(r *gin.Engine, prefix string, db *db.DB) *gin.RouterGroup { api := r.Group(prefix) api.Use(func(c *gin.Context) { c.Set("db", db) }) cardRoutes(api, "/board/") taskRoutes(api, "/task/") return api }
// RegistrarRotas realiza o registro de todas as rotas da aplicação. func RegistrarRotas(r *gin.Engine, usuario, senha string) { // Habilitando esquema de autorização simples auth := r.Group("/", gin.BasicAuth(gin.Accounts{usuario: senha})) auth.GET("/", Raiz) auth.GET("/pagina/:pag", Pagina) auth.GET("/formulario", Formulario) auth.POST("/salvar", Salvar) auth.GET("/remover/:id", Remover) auth.GET("/editar/:id", Editar) }
func LoadPage(parentRoute *gin.Engine) { //type Page struct { // Title string //} parentRoute.SetHTMLTemplate(template.Must(template.ParseFiles("frontend/canjs/templates/message.html", "frontend/canjs/templates/app.html", "frontend/canjs/templates/base.html", "frontend/canjs/templates/404.html"))) log.Debug("url : " + config.StaticUrl) log.Debug("guid : " + config.Guid) log.Debug("path : " + staticPath) parentRoute.Static(config.StaticUrl+"/"+config.Guid, staticPath) // route.ServeFiles doesn't exist in the current version of gin. If you want to use this, use the 59d949d35080b83864dbeafadecef112d46aaeee. //parentRoute.ServeFiles(config.StaticUrl+"/"+config.Guid+"/*filepath", http.Dir(staticPath)) parentRoute.NoRoute(func(c *gin.Context) { c.HTML(404, "404.html", map[string]string{"language": config.DefaultLanguage, "title": config.Title}) }) route.Route(parentRoute.Group("")) }
func SetupRoutes(r *gin.Engine, s *socketio.Server) { //Oauth Authenticaton and Callbacks r.GET("/auth/github/callback", providerCallback) r.GET("/auth/github", providerAuth) //Template Route r.GET("/templates", templateHandler) //Socket.io Route r.GET("/socket.io/", func(c *gin.Context) { s.ServeHTTP(c.Writer, c.Request) }) //Api endpoints a := r.Group("api") a.GET("/activity", getActivity) a.GET("/users", getUsers) }
// InitRoutesStats initialized routes for Stats Controller func InitRoutesStats(router *gin.Engine) { statsCtrl := &controllers.StatsController{} admin := router.Group("/stats") admin.Use(CheckPassword(), CheckAdmin()) { admin.GET("/count", statsCtrl.Count) admin.GET("/instance", statsCtrl.Instance) admin.GET("/distribution", statsCtrl.Distribution) admin.GET("/db/stats", statsCtrl.DBStats) admin.GET("/db/replSetGetConfig", statsCtrl.DBReplSetGetConfig) admin.GET("/db/serverStatus", statsCtrl.DBServerStatus) admin.GET("/db/replSetGetStatus", statsCtrl.DBReplSetGetStatus) admin.GET("/db/collections", statsCtrl.DBStatsCollections) admin.GET("/db/slowestQueries", statsCtrl.DBGetSlowestQueries) admin.GET("/checkHeaders", statsCtrl.CheckHeaders) } }
//Mount mount router func (p *Engine) Mount(r *gin.Engine) { gf := r.Group("/reading", p.Jwt.CurrentUserHandler(false)) gf.GET("/blogs", p.Cache.Page(time.Hour*24, web.Rest(p.indexBlogs))) gf.GET("/blog/*name", p.Cache.Page(time.Hour*24, p.showBlog)) gf.GET("/books", p.Cache.Page(time.Hour*24, web.Rest(p.indexBooks))) gf.GET("/book/:id", p.Cache.Page(time.Hour*24, p.indexBook)) gf.GET("/book/:id/*name", p.Cache.Page(time.Hour*24, p.showBook)) gf.GET("/dict", p.getDict) gf.POST("/dict", p.postDict) gt := r.Group("/reading", p.Jwt.CurrentUserHandler(true)) gt.DELETE("/books/:id", p.Jwt.MustAdminHandler(), web.Rest(p.deleteBook)) gt.GET("/notes", web.Rest(p.indexNotes)) gt.POST("/notes", web.Rest(p.createNote)) gt.GET("/notes/:id", web.Rest(p.showNote)) gt.POST("/notes/:id", web.Rest(p.updateNote)) gt.DELETE("/notes/:id", web.Rest(p.deleteNote)) }
// Register all endpoint handlers func Register(engine *gin.Engine) { engine.Use(Limiter) engine.Use(Recovery) dbGroup := engine.Group("") dbGroup.Use(Database) dbGroup.GET("/check", checkGet) dbGroup.POST("/request/google", requestGooglePost) dbGroup.POST("/request/saml", requestSamlPost) dbGroup.GET("/callback/google", callbackGoogleGet) dbGroup.POST("/callback/saml", callbackGoogleGet) dbGroup.GET("/update/google", updateGoogleGet) dbGroup.POST("/v1/request/google", requestGoogle2Post) dbGroup.POST("/v1/request/saml", requestSamlPost) dbGroup.GET("/v1/callback/google", callbackGoogleGet) dbGroup.POST("/v1/callback/saml", callbackSamlPost) dbGroup.GET("/v1/update/google", updateGoogleGet) }
// New returns a new ginja.Api struct func New(server *gin.Engine, config Config, middleware ...gin.HandlerFunc) *GinApi { config.ApplyDefaults() api := &GinApi{ RouterGroup: server.Group(config.buildUrl()), Api: Api{Config: config}, } api.init() api.Use(middleware...) // TODO extract! if api.MountStats { api.GET(api.StatsURL, func(c *gin.Context) { c.JSON(http.StatusOK, gin.H{"config": api.Config}) }) } return api }
//Mount mount routes func (p *Engine) Mount(r *gin.Engine) { ag := r.Group("/admin", p.Jwt.CurrentUserHandler(true), p.Jwt.MustAdminHandler()) ag.GET("/site/info", p.getAdminSiteInfo) ag.POST("/site/info", web.Rest(p.postAdminSiteInfo)) ag.DELETE("/cache", web.Rest(p.deleteAdminCache)) ag.GET("/notices", web.Rest(p.getNotices)) ag.POST("/notices", web.Rest(p.postNotices)) ag.DELETE("/notices/:id", web.Rest(p.deleteNotice)) r.GET("/notices", p.Cache.Page(time.Hour*24, web.Rest(p.getNotices))) r.GET("/personal/self", p.Jwt.CurrentUserHandler(true), web.Rest(p.getPersonalSelf)) r.GET("/personal/logs", p.Jwt.CurrentUserHandler(true), web.Rest(p.getPersonalLogs)) r.DELETE("/personal/signOut", p.Jwt.CurrentUserHandler(true), p.deleteSignOut) r.GET("/locales/:lang", p.Cache.Page(time.Hour*24, p.getLocale)) r.GET("/site/info", p.Cache.Page(time.Hour*24, p.getSiteInfo)) r.POST("/oauth2/callback", web.Rest(p.postOauth2Callback)) }
// InitRoutesGroups initialized routes for Groups Controller func InitRoutesGroups(router *gin.Engine) { groupsCtrl := &controllers.GroupsController{} g := router.Group("/") g.Use(CheckPassword()) { g.GET("/groups", groupsCtrl.List) g.PUT("/group/add/user", groupsCtrl.AddUser) g.PUT("/group/remove/user", groupsCtrl.RemoveUser) g.PUT("/group/add/adminuser", groupsCtrl.AddAdminUser) g.PUT("/group/remove/adminuser", groupsCtrl.RemoveAdminUser) admin := router.Group("/group") admin.Use(CheckPassword(), CheckAdmin()) { admin.POST("", groupsCtrl.Create) } } }