package routes import ( "fmt" "log" "github.com/flamego/binding" "github.com/flamego/flamego" "github.com/flamego/validator" "git.metaunix.net/bitgoblin/blt/models" "git.metaunix.net/bitgoblin/blt/web/forms" ) func ResultPostCreate(c flamego.Context, form forms.ResultForm, errs binding.Errors) { if len(errs) > 0 { var err error switch errs[0].Category { case binding.ErrorCategoryValidation: err = errs[0].Err.(validator.ValidationErrors)[0] default: err = errs[0].Err } log.Fatal(err) } result := models.Result{ TestID: form.Test, HardwareID: form.Hardware, BenchmarkID: form.Benchmark, AverageScore: form.AverageScore, MinimumScore: form.MinimumScore, MaximumScore: form.MaximumScore, } _ = models.DB.Create(&result) c.Redirect(fmt.Sprintf("/test/%d", result.TestID)) }