Exemplo n.º 1
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)
}
Exemplo n.º 2
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(""))
}
Exemplo n.º 3
0
func RegisterRoute(r *gin.Engine) {
	loadHTMLGlob(r, path.Join(config.GLOBAL_CONFIG.TemplatePath, "*"), registerDefaultFunctions)

	r.GET("/", IndexAction)
	r.GET("/post/:postId", ShowPostAction)

	r.POST("/login", LoginAction)
	r.POST("/register", RegisterAction)
	r.GET("/logout", LogoutAction)

	r.GET("/new_post", ShowNewPostPageAction)
	r.POST("/posts", NewPostAction)

	// admin
	r.GET("/admin/users", controllers.ShowUsersAction)

	r.Static("/statics", config.GLOBAL_CONFIG.StaticPath)

	r.NoRoute(NoRouteHandler)
}
Exemplo n.º 4
0
// Declare all routes
func Route(r *gin.Engine) {
	r.GET("/api/ping", func(c *gin.Context) {
		c.String(200, "PONG")
	})

	r.NoRoute(servePublic)

	// set up the namespace
	api := r.Group("/api")

	func(api *gin.RouterGroup) {
		api.POST("/login", login)
		api.POST("/logout", logout)
	}(api.Group("/auth"))

	api.Use(authentication)

	api.GET("/ws", sockets.Handler)

	api.GET("/info", getSystemInfo)
	api.GET("/upgrade", checkUpgrade)
	api.POST("/upgrade", doUpgrade)

	func(api *gin.RouterGroup) {
		api.GET("", getUser)
		// api.PUT("/user", misc.UpdateUser)

		api.GET("/tokens", getAPITokens)
		api.POST("/tokens", createAPIToken)
		api.DELETE("/tokens/:token_id", expireAPIToken)
	}(api.Group("/user"))

	api.GET("/projects", projects.GetProjects)
	api.POST("/projects", projects.AddProject)
	api.GET("/events", getEvents)

	api.GET("/users", getUsers)
	api.POST("/users", addUser)
	api.GET("/users/:user_id", getUserMiddleware, getUser)
	api.PUT("/users/:user_id", getUserMiddleware, updateUser)
	api.POST("/users/:user_id/password", getUserMiddleware, updateUserPassword)
	api.DELETE("/users/:user_id", getUserMiddleware, deleteUser)

	func(api *gin.RouterGroup) {
		api.Use(projects.ProjectMiddleware)

		api.GET("", projects.GetProject)
		api.PUT("", projects.MustBeAdmin, projects.UpdateProject)
		api.DELETE("", projects.MustBeAdmin, projects.DeleteProject)

		api.GET("/events", getEvents)

		api.GET("/users", projects.GetUsers)
		api.POST("/users", projects.MustBeAdmin, projects.AddUser)
		api.POST("/users/:user_id/admin", projects.MustBeAdmin, projects.UserMiddleware, projects.MakeUserAdmin)
		api.DELETE("/users/:user_id/admin", projects.MustBeAdmin, projects.UserMiddleware, projects.MakeUserAdmin)
		api.DELETE("/users/:user_id", projects.MustBeAdmin, projects.UserMiddleware, projects.RemoveUser)

		api.GET("/keys", projects.GetKeys)
		api.POST("/keys", projects.AddKey)
		api.PUT("/keys/:key_id", projects.KeyMiddleware, projects.UpdateKey)
		api.DELETE("/keys/:key_id", projects.KeyMiddleware, projects.RemoveKey)

		api.GET("/repositories", projects.GetRepositories)
		api.POST("/repositories", projects.AddRepository)
		api.PUT("/repositories/:repository_id", projects.RepositoryMiddleware, projects.UpdateRepository)
		api.DELETE("/repositories/:repository_id", projects.RepositoryMiddleware, projects.RemoveRepository)

		api.GET("/inventory", projects.GetInventory)
		api.POST("/inventory", projects.AddInventory)
		api.PUT("/inventory/:inventory_id", projects.InventoryMiddleware, projects.UpdateInventory)
		api.DELETE("/inventory/:inventory_id", projects.InventoryMiddleware, projects.RemoveInventory)

		api.GET("/environment", projects.GetEnvironment)
		api.POST("/environment", projects.AddEnvironment)
		api.PUT("/environment/:environment_id", projects.EnvironmentMiddleware, projects.UpdateEnvironment)
		api.DELETE("/environment/:environment_id", projects.EnvironmentMiddleware, projects.RemoveEnvironment)

		api.GET("/templates", projects.GetTemplates)
		api.POST("/templates", projects.AddTemplate)
		api.PUT("/templates/:template_id", projects.TemplatesMiddleware, projects.UpdateTemplate)
		api.DELETE("/templates/:template_id", projects.TemplatesMiddleware, projects.RemoveTemplate)

		api.GET("/tasks", tasks.GetAll)
		api.POST("/tasks", tasks.AddTask)
		api.GET("/tasks/:task_id/output", tasks.GetTaskMiddleware, tasks.GetTaskOutput)
		api.DELETE("/tasks/:task_id", tasks.GetTaskMiddleware, tasks.RemoveTask)
	}(api.Group("/project/:project_id"))
}