Ejemplo n.º 1
0
func sanityCheck(r *gin.Engine) {
	r.GET("/sanity-check.json", func(c *gin.Context) {

		type tool struct {
			Name        string `json:"name"`
			Description string `json:"description"`
			Homepage    string `json:"homepage"`
			Installed   bool   `json:"installed"`
		}

		var sanity = *GetSanityCheck()
		c.JSON(200, gin.H{
			"tools": []tool{
				tool{Name: "LaTeX", Description: "Compiles Tex", Homepage: "https://www.latex-project.org", Installed: sanity.latex},
				tool{Name: "pdflatex", Description: "Converts .tex to .pdf", Homepage: "https://www.latex-project.org", Installed: sanity.pdflatex},
				tool{Name: "convert", Description: "Converts .pdf to .png", Homepage: "http://www.imagemagick.org/script/index.php", Installed: sanity.convert},
			},
		})
	})
	r.GET("/sanity-check", func(c *gin.Context) {
		var sanity = *GetSanityCheck()
		c.HTML(200, "sanity-check.tmpl", gin.H{
			"latex":    sanity.latex,
			"pdflatex": sanity.pdflatex,
			"convert":  sanity.convert,
		})

	})
}
Ejemplo n.º 2
0
func NewUserResource(e *gin.Engine) {
	u := UserResource{}

	// Setup Routes
	e.GET("/users", u.getAllUsers)
	e.GET("/users/:id", u.getUserByID)
}
Ejemplo n.º 3
0
func InitRooter(e *gin.Engine) {
	e.GET("/status", func(c *gin.Context) { c.String(http.StatusOK, "ok") })

	e.GET("/searchUser", userService.ListEndpoint)
	e.GET("/searchItem", itemService.ListEndpoint)
	e.GET("/searchPost", postService.ListEndpoint)

	e.GET("/user/:id", userService.GetWebEndpoint)
	e.GET("/item/:id", itemService.GetWebEndpoint)
	e.GET("/post/:id", postService.GetWebEndpoint)

	e.Static("/static", "./static")
	//
	//	json := e.Group("/json")
	//	{
	//		json.GET("user/detail/:id", auth(), userService.GetEndpoint)
	//		json.GET("user/list", auth(), userService.ListEndpoint)
	//	}
	//
	//	web := e.Group("/web")
	//	{
	//		web.GET("user/detail/:id", auth(), userService.GetWebEndpoint)
	//		web.GET("user/list", auth(), userService.ListWebEndpoint)
	//	}
	//
	//	// However, this one will match /user/john/ and also /user/john/send
	//	// If no other routers match /user/john, it will redirect to /user/join/
	//	e.GET("/user/:name/*action", func(c *gin.Context) {
	//		name := c.Param("name")
	//		action := c.Param("action")
	//		message := name + " is " + action
	//		c.String(http.StatusOK, message)
	//	})

}
Ejemplo n.º 4
0
func AddRepoRoutes(s *store.Engine, r *gin.Engine) {
	r.GET("/users/:username/repos", func(c *gin.Context) {
		var repos []*Repo

		for _, repo := range s.State.Repos {
			if repo.RepoOwner.Username == c.Param("username") {
				repos = append(repos, repo)
			}
		}

		c.JSON(http.StatusOK, repos)
	})

	r.GET("/users/:username/repos/:reponame", func(c *gin.Context) {
		var repo *Repo

		for _, rp := range s.State.Repos {
			if rp.RepoOwner.Username == c.Param("username") &&
				rp.Name == c.Param("reponame") {
				repo = rp
				break
			}
		}

		c.JSON(http.StatusOK, repo)
	})
}
Ejemplo n.º 5
0
func defineRouting(router *gin.Engine) {
	router.POST("/answer/new", CreateAnswer)
	router.POST("/question/new", CreateQuestion)
	router.POST("/survey/new", CreateSurvey)
	router.POST("/person/new", CreatePerson)
	router.GET("/survey/:id", GetSurvey)
}
Ejemplo n.º 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)
	}
}
Ejemplo n.º 7
0
Archivo: web.go Proyecto: robvdl/gcms
// 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)
	}
}
Ejemplo n.º 8
0
func registerRoutes(e *gin.Engine) {
	controller := rc.ResourceController{}
	controller.DatabaseProvider = Database

	resourceNames := []string{"RecordMatchContext",
		"RecordMatchSystemInterface", "RecordSet"}

	for _, name := range resourceNames {
		e.GET("/"+name+"/:id", controller.GetResource)
		e.POST("/"+name, controller.CreateResource)
		e.PUT("/"+name+"/:id", controller.UpdateResource)
		e.DELETE("/"+name+"/:id", controller.DeleteResource)
		e.GET("/"+name, controller.GetResources)
	}

	e.POST("/AnswerKey", controller.SetAnswerKey)

	name := "RecordMatchRun"
	e.GET("/"+name, controller.GetResources)
	e.GET("/"+name+"/:id", controller.GetResource)
	e.POST("/"+name, rc.CreateRecordMatchRunHandler(Database))
	e.PUT("/"+name+"/:id", controller.UpdateResource)
	e.DELETE("/"+name+"/:id", controller.DeleteResource)

	e.GET("/RecordMatchRunMetrics", rc.GetRecordMatchRunMetricsHandler(Database))
	e.GET("/RecordMatchRunLinks/:id", rc.GetRecordMatchRunLinksHandler(Database))

	e.Static("/ptmatch/api/", "api")
}
Ejemplo n.º 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)
		}
	}
}
Ejemplo n.º 10
0
func Register(r *gin.Engine) {
	api(r.Group("/api"))

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

}
func (h *UserHandlers) RegisterHandlers(g *gin.Engine) {
	g.GET("/user", h.All)
	g.GET("/user/:id", h.GetUser)
	g.PUT("/user", h.CreateUser)
	g.POST("/user/:id", h.UpdateUser)
	g.DELETE("/user/:id", h.DeleteUser)
	g.POST("/user/:id/password", h.ChangePassword)
}
Ejemplo n.º 12
0
//Setup gin Engine server
func initGin(ginEngine *gin.Engine) {
	ginEngine.Use(logrusLogger())
	ginEngine.POST("/assignment", putAssignment)
	ginEngine.POST("/submission", putSubmission)
	ginEngine.GET("/plugin/langs", getSupportedLangs)
	ginEngine.GET("/debug/vars", expvarGin.Handler())
	ginEngine.GET("/health", healthCheck)
}
Ejemplo n.º 13
0
func main() {
	flag.Parse()
	if *logToFile {
		logWriteTo, err := os.OpenFile(logFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
		if err != nil {
			log.Printf("error opening to log file: %v", err)
		}
		if logWriteTo != nil {
			log.SetOutput(logWriteTo)
		}
	}
	gin.SetMode(*ginMode)
	var route *gin.Engine
	if *useGinLogger {
		route = gin.Default()
	} else {
		route = gin.New()
		route.Use(logger)
	}

	route.GET("/", func(ctx *gin.Context) {
		ctx.JSON(200, gin.H{"message": "Its an entry point :)"})
	})

	route.GET("/token", func(ctx *gin.Context) {
		tokenString := auth.GetToken(secretpassword)
		ctx.JSON(200, gin.H{"token": tokenString})
	})
	route.GET("/dbaccessor", func(ctx *gin.Context) {
		ctx.JSON(200, getFakeDbData())
	})
	route.Use(auth.Auth(secretpassword))
	route.POST("/auth", func(ctx *gin.Context) {
		ak := ctx.Request.FormValue("authkey")
		if ak == "" {
			ctx.JSON(401, "No auth key")
		} else if !auth.VerifyAuthKey(ak) {
			ctx.JSON(401, "Wrong key")
		} else {
			ctx.Redirect(http.StatusFound, "/user")
		}
	})
	route.GET("/user", func(ctx *gin.Context) {
		key := ctx.MustGet("authKey")
		udetails := dbAccessor(key.(string))
		ctx.JSON(200, gin.H{"user": udetails})
	})
	route.GET("/user/:id", func(ctx *gin.Context) {
		id := ctx.Params.ByName("id")
		ctx.JSON(200, find(id))
	})

	if err := route.Run(fmt.Sprintf(":%d", *port)); err != nil {
		logFatal("Http not running: ", err)
	} else {
		logPrintln("shutting down")
	}
}
Ejemplo n.º 14
0
// Controller for taxonomies resources
func Controller(r *gin.Engine, db *sql.DB) {
	r.GET("/taxonomies", func(c *gin.Context) {
		taxonomies, err := ListAllTaxonomies(db)
		if err != nil {
			c.AbortWithError(400, err)
			return
		}
		c.Header("Content-Type", "application/json")
		c.String(200, taxonomies)
	})
	r.POST("/taxonomy", func(c *gin.Context) {
		tax := new(Taxonomy)
		err := c.BindJSON(&tax)
		if err != nil {
			c.Error(err)
			return
		}
		err = CreateTaxonomy(tax, db)
		if err != nil {
			c.AbortWithError(400, err)
			return
		}
		c.String(200, "")
	})
	r.DELETE("/taxonomy/:id", func(c *gin.Context) {
		defer func() {
			if r := recover(); r != nil {
				c.AbortWithError(400, r.(error))
			}
		}()
		id := getID(c)
		err := DeleteTaxonomy(id, db)
		if err != nil {
			panic(err)
		}
		c.String(200, "")
	})
	r.PUT("/taxonomy/:id", func(c *gin.Context) {
		defer func() {
			if r := recover(); r != nil {
				c.AbortWithError(400, r.(error))
			}
		}()
		id := getID(c)

		tax := new(Taxonomy)
		err := c.BindJSON(&tax)
		if err != nil {
			panic(err)
		}
		err = UpdateTaxonomy(id, tax, db)
		if err != nil {
			c.AbortWithError(400, err)
			return
		}
		c.String(200, "")
	})
}
Ejemplo n.º 15
0
func (h *StaticHandler) Setup(engine *gin.Engine) {
	fs := gin.Dir(h.Root, false)
	h.fileServer = http.StripPrefix("/", http.FileServer(fs))

	engine.GET("/*filepath", h.Handle)
	engine.HEAD("/*filepath", h.Handle)

	return
}
Ejemplo n.º 16
0
func bindPages(router *gin.Engine) {
	pages := []db.Page{}
	db.DB.Find(&pages)
	for _, page := range pages {
		if !strings.HasPrefix(page.Url, "/") {
			page.Url = "/" + page.Url
		}
		router.GET(page.Url, controllers.ViewPageHandler)
	}
}
Ejemplo n.º 17
0
func GetAllUserHttpSession(db gorm.DB, router *gin.Engine) {

	// GET /user_http_session
	// GET all user_http_session
	router.GET("/user_http_session", func(c *gin.Context) {
		var user_http_session []model.UserHttpSession
		db.Find(&user_http_session)
		c.JSON(http.StatusOK, user_http_session)
	})
}
Ejemplo n.º 18
0
func GetAllLike(db gorm.DB, router *gin.Engine) {

	// GET /like
	// GET all like
	router.GET("/like", func(c *gin.Context) {
		var like []model.Like
		db.Find(&like)
		c.JSON(http.StatusOK, like)
	})
}
Ejemplo n.º 19
0
func GetAllMigration(db gorm.DB, router *gin.Engine) {

	// GET /migration
	// GET all migration
	router.GET("/migration", func(c *gin.Context) {
		var migration []model.Migration
		db.Find(&migration)
		c.JSON(http.StatusOK, migration)
	})
}
Ejemplo n.º 20
0
func GetAllUserSetting(db gorm.DB, router *gin.Engine) {

	// GET /user_setting
	// GET all user_setting
	router.GET("/user_setting", func(c *gin.Context) {
		var user_setting []model.UserSetting
		db.Find(&user_setting)
		c.JSON(http.StatusOK, user_setting)
	})
}
Ejemplo n.º 21
0
func GetAllWallEntry(db gorm.DB, router *gin.Engine) {

	// GET /wall_entry
	// GET all wall_entry
	router.GET("/wall_entry", func(c *gin.Context) {
		var wall_entry []model.WallEntry
		db.Find(&wall_entry)
		c.JSON(http.StatusOK, wall_entry)
	})
}
Ejemplo n.º 22
0
func GetAllActivity(db gorm.DB, router *gin.Engine) {

	// GET /activity
	// GET all activity
	router.GET("/activity", func(c *gin.Context) {
		var activity []model.Activity
		db.Find(&activity)
		c.JSON(http.StatusOK, activity)
	})
}
Ejemplo n.º 23
0
func GetAllGroupAdmin(db gorm.DB, router *gin.Engine) {

	// GET /group_admin
	// GET all group_admin
	router.GET("/group_admin", func(c *gin.Context) {
		var group_admin []model.GroupAdmin
		db.Find(&group_admin)
		c.JSON(http.StatusOK, group_admin)
	})
}
Ejemplo n.º 24
0
func GetAllUserFollow(db gorm.DB, router *gin.Engine) {

	// GET /user_follow
	// GET all user_follow
	router.GET("/user_follow", func(c *gin.Context) {
		var user_follow []model.UserFollow
		db.Find(&user_follow)
		c.JSON(http.StatusOK, user_follow)
	})
}
Ejemplo n.º 25
0
func GetAllLogging(db gorm.DB, router *gin.Engine) {

	// GET /logging
	// GET all logging
	router.GET("/logging", func(c *gin.Context) {
		var logging []model.Logging
		db.Find(&logging)
		c.JSON(http.StatusOK, logging)
	})
}
Ejemplo n.º 26
0
func GetAllNotification(db gorm.DB, router *gin.Engine) {

	// GET /notification
	// GET all notification
	router.GET("/notification", func(c *gin.Context) {
		var notification []model.Notification
		db.Find(&notification)
		c.JSON(http.StatusOK, notification)
	})
}
Ejemplo n.º 27
0
func GetAllSpaceSetting(db gorm.DB, router *gin.Engine) {

	// GET /space_setting
	// GET all space_setting
	router.GET("/space_setting", func(c *gin.Context) {
		var space_setting []model.SpaceSetting
		db.Find(&space_setting)
		c.JSON(http.StatusOK, space_setting)
	})
}
Ejemplo n.º 28
0
func GetAllUserPassword(db gorm.DB, router *gin.Engine) {

	// GET /user_password
	// GET all user_password
	router.GET("/user_password", func(c *gin.Context) {
		var user_password []model.UserPassword
		db.Find(&user_password)
		c.JSON(http.StatusOK, user_password)
	})
}
Ejemplo n.º 29
0
func GetAllUserInvite(db gorm.DB, router *gin.Engine) {

	// GET /user_invite
	// GET all user_invite
	router.GET("/user_invite", func(c *gin.Context) {
		var user_invite []model.UserInvite
		db.Find(&user_invite)
		c.JSON(http.StatusOK, user_invite)
	})
}
Ejemplo n.º 30
0
func (tr *TemplatesResource) RegisterRoutes(c *gin.Engine) {
	c.GET("/api/templates", tr.Index)
	c.GET("/api/templates/:id", tr.Show)
	c.POST("/api/templates", tr.Create)
	c.POST("/api/templates/:id", tr.Update)
	c.PUT("/api/templates/:id", tr.Update)
	c.DELETE("/api/templates/:id", tr.Delete)
	c.POST("/api/templates/:id/convert", tr.Convert)
	c.POST("/api/convert", tr.ConvertRaw)
}