Beispiel #1
6
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)
}
Beispiel #3
0
func registerRoutes(server *gin.Engine) {
	podRoute := server.Group("/pod")
	{
		podRoute.POST("/create", PodCreate)
		podRoute.GET("/state/:pod", PodState)
	}
}
Beispiel #4
0
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()
	})
}
Beispiel #5
0
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)
		}
	}

}
Beispiel #6
0
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)
	}
}
Beispiel #7
0
// 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)
	}
}
Beispiel #8
0
// 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)
	}
}
Beispiel #9
0
// 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)
		}
	}
}
Beispiel #10
0
// 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)
	}
}
Beispiel #11
0
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)
}
Beispiel #12
0
func Register(r *gin.Engine) {
	api(r.Group("/api"))

	r.GET("/", showIndex)
	r.GET("/h/:_", showIndex)
	r.GET("/p/:_", showIndex)

}
Beispiel #13
0
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())
	}
}
Beispiel #14
0
// 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)
}
Beispiel #15
0
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)
	}
}
Beispiel #16
0
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)
	}
}
Beispiel #17
0
// 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)
	}
}
Beispiel #18
0
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
}
Beispiel #19
0
// 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)
	}

}
Beispiel #20
0
//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))
}
Beispiel #21
0
Datei: api.go Projekt: fmr/kanban
/*
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

}
Beispiel #22
0
// 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)
}
Beispiel #23
0
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(""))
}
Beispiel #24
0
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)
}
Beispiel #25
0
// 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)
	}
}
Beispiel #26
0
//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))
}
Beispiel #27
0
// 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)
}
Beispiel #28
0
// 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
}
Beispiel #29
0
//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))
}
Beispiel #30
0
// 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)
		}
	}
}