frontend: move time in a separate package to be used elsewhere
This commit is contained in:
parent
5c45bb5127
commit
6ee9b342f1
@ -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))
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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)
|
Loading…
Reference in New Issue
Block a user