func main() { userFlag := flag.Bool("add_user", false, "Run CLI for adding user to database") testFlag := flag.Bool("test", false, "Run test script to simulate client") flag.Parse() // Connect to database data := os.Getenv("OPENSHIFT_DATA_DIR") db := models.InitDb(data+"ota.sql", data+"builds") defer db.Db.Close() go models.RefreshBuilds() if *testFlag { tests.TestServer("http://localhost:8080") } else { if *userFlag { // Start CLI to create new user account addUser() } else { // Start server templates := "./views" controllers.InitMiddleware(templates) server(templates) } } }
// POST /releases/delete func DeleteReleases(w http.ResponseWriter, r *http.Request) { r.ParseForm() id, _ := strconv.ParseInt(r.FormValue("Id"), 10, 64) release := models.FindRelease(id) file := models.FindFile(release.FileId) // Delete from DB models.DeleteRelease(release) models.UnpublishFile(file) go models.RefreshBuilds() http.Redirect(w, r, "/admin/releases", http.StatusFound) }
// POST /releases/create func CreateReleases(w http.ResponseWriter, r *http.Request) { r.ParseForm() fileId, _ := strconv.ParseInt(r.FormValue("FileId"), 10, 64) file := models.FindFile(fileId) // Generate release release := models.Release{ Created: time.Now().UnixNano(), Changelog: r.FormValue("Changelog"), Channel: r.FormValue("Channel"), FileId: file.Id, FileName: file.Name, } models.CreateRelease(release) models.PublishFile(file) go models.RefreshBuilds() http.Redirect(w, r, "/admin/releases", http.StatusFound) }
// GET /files/refresh func RefreshFiles(w http.ResponseWriter, r *http.Request) { models.RefreshBuilds() http.Redirect(w, r, "/admin/files", http.StatusFound) }