func (this *Handler) Edit(tableName string) { sess := this.Session.SessionStart(this.Response, this.Request) createTime := sess.Get("createTime") life := this.Session.Maxlifetime if createTime.(int64)+life < time.Now().Unix() { this.Session.SessionDestroy(this.Response, this.Request) fmt.Println("Edit - Destroy") tmp, err := template.ParseFiles( "view/index.html", "view/header.html", "view/footer.html") utils.HandleErr("[handler.select] ParseFiles: ", err) err = tmp.ExecuteTemplate(this.Response, "index", nil) utils.HandleErr("[handler.select] ExecuteTemplate: ", err) return } sess.Set("createTime", time.Now().Unix()) oper := this.Request.FormValue("oper") base := new(models.ModelManager) var model models.Entity switch tableName { case "Users": model = base.Users().Entity break case "Contests": model = base.Contests().Entity break case "Blanks": model = base.Blanks().Entity break } params := make([]interface{}, len(model.Columns)-1) for i := 0; i < len(model.Columns)-1 && this.Request.FormValue(model.Columns[i+1]) != ""; i++ { if model.Columns[i+1] == "date" { params[i] = this.Request.FormValue(model.Columns[i+1])[0:10] } else { params[i] = this.Request.FormValue(model.Columns[i+1]) } } switch oper { case "edit": model.Update(model.Columns[1:], params, fmt.Sprintf("id=%s", this.Request.FormValue("id"))) break case "add": model.Insert(model.Columns[1:], params) if tableName == "Contests" { id := connect.DBGetLastInsertedId(tableName) models.CreateBlank(id) fmt.Println("last inserted id: ", id) } break case "del": ids := strings.Split(this.Request.FormValue("id"), ",") p := make([]interface{}, len(ids)) for i, v := range ids { p[i] = interface{}(v) } model.Delete("id", p) break } }