func addNewProject(c *gin.Context) { nwo := strings.TrimSpace(c.PostForm("repo")) if nwo == "" { render.New(c).HTML(http.StatusOK, "add.tmpl", add{fmt.Errorf("the repository name cannot be empty")}) return } if err := github.AddProject(nwo); err != nil { render.New(c).HTML(http.StatusOK, "add.tmpl", add{err}) return } showProjects(c) }
func showProjects(c *gin.Context) { projects, err := db.ListProjects() if err != nil { c.HTML(http.StatusInternalServerError, "error.tmpl", nil) return } var prs []project for _, p := range projects { lr := getLatestRelease(p) rc := getRcRelease(p) prs = append(prs, project{p.Owner(), p.Repo(), lr, rc}) } render.New(c).HTML(http.StatusOK, "index.tmpl", index{prs}) }
func startServer(port uint, adminPassword string) { router := gin.Default() router.Static("/assets", "./assets") router.GET("/", func(c *gin.Context) { showProjects(c) }) authorized := router.Group("/add", gin.BasicAuth(gin.Accounts{ "admin": adminPassword, })) authorized.GET("", func(c *gin.Context) { render.New(c).HTML(http.StatusOK, "add.tmpl", nil) }) authorized.POST("", func(c *gin.Context) { addNewProject(c) }) router.Run(fmt.Sprintf(":%v", port)) }