diff --git a/admin/api_file.go b/admin/api_file.go index 20392030..f77e6d9a 100644 --- a/admin/api_file.go +++ b/admin/api_file.go @@ -44,7 +44,7 @@ func createExerciceFile(theme fic.Theme, exercice fic.Exercice, args []string, b return exercice.ImportFile(pathname, uf.URI) } -func getCloudFile(pathname string, dest string) (error) { +func getCloudFile(pathname string, dest string) error { client := http.Client{} if req, err := http.NewRequest("GET", CloudDAVBase+pathname, nil); err != nil { return err @@ -58,7 +58,7 @@ func getCloudFile(pathname string, dest string) (error) { if fd, err := os.Create(dest); err != nil { return err } else { - defer fd.Close(); + defer fd.Close() if resp.StatusCode != http.StatusOK { return errors.New(resp.Status) diff --git a/admin/api_theme.go b/admin/api_theme.go index 599c4794..5d1f4bea 100644 --- a/admin/api_theme.go +++ b/admin/api_theme.go @@ -17,14 +17,14 @@ var ApiThemesRouting = map[string]DispatchFunction{ } type exportedExercice struct { - Title string `json:"title"` - Gain int64 `json:"gain"` - Solved int64 `json:"solved"` + Title string `json:"title"` + Gain int64 `json:"gain"` + Solved int64 `json:"solved"` } type exportedTheme struct { - Name string `json:"name"` - Authors string `json:"authors"` + Name string `json:"name"` + Authors string `json:"authors"` Exercices map[string]exportedExercice `json:"exercices"` } diff --git a/admin/static.go b/admin/static.go index c0eb7ae3..6c7b7cc6 100644 --- a/admin/static.go +++ b/admin/static.go @@ -5,7 +5,7 @@ import ( "path" ) -type staticRouting struct{ +type staticRouting struct { StaticDir string } diff --git a/backend/submission.go b/backend/submission.go index db0e0d71..ecd35495 100644 --- a/backend/submission.go +++ b/backend/submission.go @@ -62,7 +62,7 @@ func genTeamMyFile(team fic.Team) error { if s, err := os.Stat(dirPath); os.IsNotExist(err) { os.MkdirAll(dirPath, 0777) - } else if ! s.IsDir() { + } else if !s.IsDir() { return errors.New("dirPath is not a directory") } diff --git a/frontend/main.go b/frontend/main.go index bbddaef8..73754be3 100644 --- a/frontend/main.go +++ b/frontend/main.go @@ -29,8 +29,8 @@ func touchStartedFile(startSub time.Duration) { func main() { var bind = flag.String("bind", "0.0.0.0:8080", "Bind port/socket") var prefix = flag.String("prefix", "", "Request path prefix to strip (from proxy)") - var start = flag.Int64("start", 0, fmt.Sprintf("Challenge start timestamp (in 2 minutes: %d)", time.Now().Unix() / 60 * 60 + 120)) - var duration = flag.Duration("duration", 180 * time.Minute, "Challenge duration") + var start = flag.Int64("start", 0, fmt.Sprintf("Challenge start timestamp (in 2 minutes: %d)", time.Now().Unix()/60*60+120)) + var duration = flag.Duration("duration", 180*time.Minute, "Challenge duration") flag.StringVar(&TeamsDir, "teams", "../TEAMS", "Base directory where save teams JSON files") flag.StringVar(&SubmissionDir, "submission", "./submissions/", "Base directory where save submissions") flag.Parse() diff --git a/frontend/submit.go b/frontend/submit.go index 75918761..ca0bbdaa 100644 --- a/frontend/submit.go +++ b/frontend/submit.go @@ -11,7 +11,7 @@ import ( "time" ) -type SubmissionHandler struct{ +type SubmissionHandler struct { ChallengeEnd time.Time } @@ -20,7 +20,6 @@ func (s SubmissionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") - // Check request type and size if r.Method != "POST" { http.Error(w, "{\"errmsg\":\"Requête invalide.\"}", http.StatusBadRequest) @@ -30,7 +29,6 @@ func (s SubmissionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { return } - // Extract URL arguments var sURL = strings.Split(r.URL.Path, "/") @@ -61,14 +59,12 @@ func (s SubmissionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } } - // Previous submission not treated if _, err := os.Stat(path.Join(SubmissionDir, fmt.Sprintf("%d", team), fmt.Sprintf("%d", exercice))); !os.IsNotExist(err) { http.Error(w, "{\"errmsg\":\"Du calme ! une tentative est déjà en cours de traitement.\"}", http.StatusPaymentRequired) return } - // Read request body var body []byte if r.ContentLength > 0 { @@ -84,7 +80,6 @@ func (s SubmissionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } } - // Store content in file if file, err := os.Create(path.Join(SubmissionDir, fmt.Sprintf("%d", team), fmt.Sprintf("%d", exercice))); err != nil { log.Println("Unable to open exercice file:", err) diff --git a/frontend/time.go b/frontend/time.go index 202e98eb..895107b5 100644 --- a/frontend/time.go +++ b/frontend/time.go @@ -7,15 +7,15 @@ import ( "time" ) -type TimeHandler struct{ +type TimeHandler struct { StartTime time.Time Duration time.Duration } type timeObject struct { - Started int64 `json:"st"` - Time int64 `json:"cu"` - Duration int `json:"du"` + Started int64 `json:"st"` + Time int64 `json:"cu"` + Duration int `json:"du"` } func (t TimeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { diff --git a/libfic/db.go b/libfic/db.go index 7547f411..7658a686 100644 --- a/libfic/db.go +++ b/libfic/db.go @@ -23,8 +23,8 @@ CREATE TABLE IF NOT EXISTS themes( authors VARCHAR(255) NOT NULL ); `); err != nil { - return err -} + return err + } if _, err := db.Exec(` CREATE TABLE IF NOT EXISTS teams( id_team INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -32,8 +32,8 @@ CREATE TABLE IF NOT EXISTS teams( color INTEGER NOT NULL ); `); err != nil { - return err -} + return err + } if _, err := db.Exec(` CREATE TABLE IF NOT EXISTS team_members( id_member INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -45,8 +45,8 @@ CREATE TABLE IF NOT EXISTS team_members( FOREIGN KEY(id_team) REFERENCES teams(id_team) ); `); err != nil { - return err -} + return err + } if _, err := db.Exec(` CREATE TABLE IF NOT EXISTS exercices( id_exercice INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -61,8 +61,8 @@ CREATE TABLE IF NOT EXISTS exercices( FOREIGN KEY(depend) REFERENCES exercices(id_exercice) ); `); err != nil { - return err -} + return err + } if _, err := db.Exec(` CREATE TABLE IF NOT EXISTS exercice_files( id_file INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -75,8 +75,8 @@ CREATE TABLE IF NOT EXISTS exercice_files( FOREIGN KEY(id_exercice) REFERENCES exercices(id_exercice) ); `); err != nil { - return err -} + return err + } if _, err := db.Exec(` CREATE TABLE IF NOT EXISTS exercice_keys( id_key INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT, @@ -86,8 +86,8 @@ CREATE TABLE IF NOT EXISTS exercice_keys( FOREIGN KEY(id_exercice) REFERENCES exercices(id_exercice) ); `); err != nil { - return err -} + return err + } if _, err := db.Exec(` CREATE TABLE IF NOT EXISTS exercice_solved( id_exercice INTEGER NOT NULL, @@ -97,8 +97,8 @@ CREATE TABLE IF NOT EXISTS exercice_solved( FOREIGN KEY(id_team) REFERENCES teams(id_team) ); `); err != nil { - return err -} + return err + } if _, err := db.Exec(` CREATE TABLE IF NOT EXISTS exercice_tries( id_exercice INTEGER NOT NULL, @@ -108,8 +108,8 @@ CREATE TABLE IF NOT EXISTS exercice_tries( FOREIGN KEY(id_team) REFERENCES teams(id_team) ); `); err != nil { - return err -} + return err + } return nil }