package main import ( "log" "net/http" "github.com/gin-contrib/cors" "github.com/gin-gonic/gin" ) type RelayRequest struct { SolverTimes SolverTimes `json:"solvers"` Events []Event `json:"events"` } func main() { r := gin.Default() r.Use(cors.Default()) r.POST("/relay", func(c *gin.Context) { var req RelayRequest if c.BindJSON(&req) == nil { log.Println(req) participants := []Solver{} for s := range req.SolverTimes { participants = append(participants, s) } if len(participants) == 0 { c.JSON(http.StatusBadRequest, gin.H{ "error": "list of participants is empty", }) return } if len(participants) > 4 { c.JSON(http.StatusBadRequest, gin.H{ "error": "too many participants", }) return } if len(req.Events) > 11 { c.JSON(http.StatusBadRequest, gin.H{ "error": "too many events", }) return } assignment := Assign(participants, req.SolverTimes, req.Events) log.Println(assignment) c.JSON(http.StatusOK, gin.H{ "response": assignment, }) } }) r.Run("0.0.0.0:1308") // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080") }