diff --git a/frontend/main.go b/frontend/main.go index dd23c330..30c6cb31 100644 --- a/frontend/main.go +++ b/frontend/main.go @@ -9,6 +9,7 @@ import ( "path" "time" + fronttime "srs.epita.fr/fic-server/frontend/time" "srs.epita.fr/fic-server/settings" ) @@ -29,7 +30,7 @@ func touchStartedFile() { } func reloadSettings(config settings.FICSettings) { - if challengeStart != config.Start || challengeEnd != config.End { + if fronttime.ChallengeStart != config.Start || fronttime.ChallengeEnd != config.End { if touchTimer != nil { touchTimer.Stop() } @@ -48,8 +49,8 @@ func reloadSettings(config settings.FICSettings) { } log.Println("Challenge ends on", config.End) - challengeStart = config.Start - challengeEnd = config.End + fronttime.ChallengeStart = config.Start + fronttime.ChallengeEnd = config.End } else { log.Println("Configuration reloaded, but start/end times doesn't change.") } @@ -86,7 +87,7 @@ func main() { http.Handle(fmt.Sprintf("%s/registration", *prefix), http.StripPrefix(fmt.Sprintf("%s/registration", *prefix), RegistrationHandler{})) http.Handle(fmt.Sprintf("%s/resolution/", *prefix), http.StripPrefix(fmt.Sprintf("%s/resolution/", *prefix), ResolutionHandler{})) http.Handle(fmt.Sprintf("%s/submission/", *prefix), http.StripPrefix(fmt.Sprintf("%s/submission/", *prefix), SubmissionHandler{})) - http.Handle(fmt.Sprintf("%s/time.json", *prefix), http.StripPrefix(*prefix, TimeHandler{})) + http.Handle(fmt.Sprintf("%s/time.json", *prefix), http.StripPrefix(*prefix, fronttime.TimeHandler{})) // Serve pages log.Println(fmt.Sprintf("Ready, listening on %s", *bind)) diff --git a/frontend/submit.go b/frontend/submit.go index 09485004..201be4a4 100644 --- a/frontend/submit.go +++ b/frontend/submit.go @@ -7,9 +7,9 @@ import ( "strconv" "strings" "time" -) -var challengeEnd time.Time = time.Unix(0, 0) + fronttime "srs.epita.fr/fic-server/frontend/time" +) type SubmissionHandler struct {} @@ -36,7 +36,7 @@ func (s SubmissionHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } team := sURL[0] - if time.Now().Sub(challengeEnd) > 0 { + if time.Now().Sub(fronttime.ChallengeEnd) > 0 { http.Error(w, "{\"errmsg\":\"Vous ne pouvez plus soumettre, le challenge est terminé.\"}", http.StatusForbidden) return } diff --git a/frontend/time.go b/frontend/time/time.go similarity index 73% rename from frontend/time.go rename to frontend/time/time.go index aa1fbb6a..42db8dc2 100644 --- a/frontend/time.go +++ b/frontend/time/time.go @@ -1,4 +1,4 @@ -package main +package time import ( "encoding/json" @@ -8,7 +8,8 @@ import ( "time" ) -var challengeStart time.Time +var ChallengeStart time.Time +var ChallengeEnd time.Time = time.Unix(0, 0) type TimeHandler struct {} @@ -23,7 +24,7 @@ func (t TimeHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") - if j, err := json.Marshal(timeObject{challengeStart.Unix(), time.Now().Unix(), int(challengeEnd.Sub(challengeStart).Seconds())}); err != nil { + if j, err := json.Marshal(timeObject{ChallengeStart.Unix(), time.Now().Unix(), int(ChallengeEnd.Sub(ChallengeStart).Seconds())}); err != nil { http.Error(w, fmt.Sprintf("{\"errmsg\":\"%q\"}", err), http.StatusInternalServerError) } else { w.WriteHeader(http.StatusOK)