package hoboken import ( "net/http" "github.com/gin-gonic/gin" ) func Listen(host string, p *Projects) { r := gin.Default() r.GET("/", func(c *gin.Context) { for _, x := range p.projects { c.String(http.StatusOK, "%s\n", x.Name) } }) r.GET("/hook", func(c *gin.Context) { project := c.Query("project") if project == "" { c.AbortWithStatus(http.StatusBadRequest) } p.RLock() defer p.RUnlock() for _, x := range p.projects { if x.Name == project { err := x.Exec() if err != nil { c.String(http.StatusInternalServerError, "Err, didn't run") return } c.String(http.StatusOK, "Successfully ran") return } } c.String(http.StatusBadRequest, "No such project") }) r.Run(host) }