format
This commit is contained in:
parent
8788eea4f0
commit
645f40f0c6
8 changed files with 32 additions and 37 deletions
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Reference in a new issue