func (this *ProblemController) Insert(w http.ResponseWriter, r *http.Request) { class.Logger.Debug("Admin Problem Insert") if r.Method != "POST" { this.Err400(w, r, "Error", "Error Method to Insert problem") return } this.Init(w, r) if this.Privilege != config.PrivilegeAD { this.Err400(w, r, "Warning", "Error Privilege to Insert problem") return } one := model.Problem{} one.Title = r.FormValue("title") time, err := strconv.Atoi(r.FormValue("time")) if err != nil { http.Error(w, "The value 'Time' is neither too short nor too large", 400) return } one.Time = time memory, err := strconv.Atoi(r.FormValue("memory")) if err != nil { http.Error(w, "The value 'Memory' is neither too short nor too large", 400) return } one.Memory = memory if special := r.FormValue("special"); special == "" { one.Special = 0 } else { one.Special = 1 } in := r.FormValue("in") out := r.FormValue("out") one.Description = template.HTML(r.FormValue("description")) one.Input = template.HTML(r.FormValue("input")) one.Output = template.HTML(r.FormValue("output")) one.In = in one.Out = out one.Source = r.FormValue("source") one.Hint = r.FormValue("hint") problemModel := model.ProblemModel{} pid, err := problemModel.Insert(one) if err != nil { http.Error(w, err.Error(), 500) return } createfile(config.Datapath+strconv.Itoa(pid), "sample.in", in) createfile(config.Datapath+strconv.Itoa(pid), "sample.out", out) http.Redirect(w, r, "/admin/problem?list", http.StatusFound) }