//@URL: /profile @method: POST func (uc *UserController) Update() { restweb.Logger.Debug("User Update") var one model.User one.Nick = uc.Input.Get("user[nick]") one.Mail = uc.Input.Get("user[mail]") one.School = uc.Input.Get("user[school]") one.Motto = uc.Input.Get("user[motto]") one.ShareCode, _ = strconv.ParseBool(uc.Input.Get("user[share_code]")) restweb.Logger.Debug(uc.Input.Get("user[share_code]")) restweb.Logger.Debug(one.ShareCode) if one.Nick == "" { hint := make(map[string]string) hint["nick"] = "Nick should not be empty." uc.W.WriteHeader(400) b, _ := json.Marshal(&hint) uc.W.Write(b) } else { userModel := model.UserModel{} err := userModel.Update(uc.Uid, one) if err != nil { http.Error(uc.W, err.Error(), 500) return } uc.W.WriteHeader(200) } }
//@URL: /sess @method: POST func (s *SessController) Post() { restweb.Logger.Debug("User Login") uid := s.Input.Get("user[handle]") pwd := s.Input.Get("user[password]") userModel := model.UserModel{} ret, err := userModel.Login(uid, pwd) if err != nil { restweb.Logger.Debug(err) s.Error(err.Error(), 500) return } if ret.Uid == "" { s.W.WriteHeader(400) } else { s.SetSession("Uid", uid) s.SetSession("Privilege", strconv.Itoa(ret.Privilege)) s.W.WriteHeader(201) // remoteAddr := s.R.Header.Get("X-Real-IP") // if you set niginx as reverse proxy remoteAddr := strings.Split(s.R.RemoteAddr, ":")[0] // otherwise userModel.RecordIP(uid, remoteAddr, time.Now().Unix()) } }
func (this *UserController) Detail(w http.ResponseWriter, r *http.Request) { class.Logger.Debug("User Detail") this.Init(w, r) args := this.ParseURL(r.URL.String()) uid := args["uid"] userModel := model.UserModel{} one, err := userModel.Detail(uid) if err != nil { http.Error(w, err.Error(), 400) return } this.Data["Detail"] = one solutionModle := model.SolutionModel{} solvedList, err := solutionModle.Achieve(uid) if err != nil { http.Error(w, err.Error(), 400) return } this.Data["List"] = solvedList //class.Logger.Debug(solvedList) this.Data["Title"] = "User Detail" if uid != "" && uid == this.Uid { this.Data["IsSettings"] = true this.Data["IsSettingsDetail"] = true } err = this.Execute(w, "view/layout.tpl", "view/user_detail.tpl") if err != nil { http.Error(w, err.Error(), 500) return } }
func (this *UserController) Edit(w http.ResponseWriter, r *http.Request) { class.Logger.Debug("User Edit") this.Init(w, r) if this.Privilege == config.PrivilegeNA { this.Data["Title"] = "Warning" this.Data["Info"] = "You must login!" err := this.Execute(w, "view/layout.tpl", "view/400.tpl") if err != nil { http.Error(w, "tpl error", 500) return } return } uid := this.Uid userModel := model.UserModel{} one, err := userModel.Detail(uid) if err != nil { http.Error(w, err.Error(), 400) return } this.Data["Detail"] = one this.Data["Title"] = "User Edit" this.Data["IsSettings"] = true this.Data["IsSettingsEdit"] = true err = this.Execute(w, "view/layout.tpl", "view/user_edit.tpl") if err != nil { http.Error(w, "tpl error", 500) return } }
func (this *UserController) List(w http.ResponseWriter, r *http.Request) { class.Logger.Debug("Admin Privilege User List") this.Init(w, r) if this.Privilege != config.PrivilegeAD { class.Logger.Info(r.RemoteAddr + " " + this.Uid + " try to visit Admin page") this.Data["Title"] = "Warning" this.Data["Info"] = "You are not admin!" err := this.Execute(w, "view/layout.tpl", "view/400.tpl") if err != nil { http.Error(w, "tpl error", 500) return } return } userModel := model.UserModel{} userlist, err := userModel.List(nil) if err != nil { http.Error(w, err.Error(), 500) return } this.Data["User"] = userlist this.Data["Title"] = "Privilege User List" this.Data["IsUser"] = true this.Data["IsList"] = true err = this.Execute(w, "view/admin/layout.tpl", "view/admin/user_list.tpl") if err != nil { http.Error(w, "tpl error", 500) return } }
//@URL: /users @method:POST func (uc *UserController) Register() { restweb.Logger.Debug("User Register") var one model.User userModel := model.UserModel{} uid := uc.Input.Get("user[handle]") nick := uc.Input.Get("user[nick]") pwd := uc.Input.Get("user[password]") pwdConfirm := uc.Input.Get("user[confirmPassword]") one.Mail = uc.Input.Get("user[mail]") one.School = uc.Input.Get("user[school]") one.Motto = uc.Input.Get("user[motto]") valid := restweb.Validation{} valid.MinSize(uid, 4, "uid") valid.Match(uid, "\\w+", "uid") if !valid.HasError { _, err := userModel.Detail(uid) if err != nil && err != model.NotFoundErr { http.Error(uc.W, err.Error(), 500) return } else if err == nil { valid.AppendError("uid", "Handle is currently in use.") } } valid.Required(nick, "nick") valid.MinSize(pwd, 6, "pwd") valid.Equal(pwd, pwdConfirm, "pwdConfirm") valid.Mail(one.Mail, "mail") if !valid.HasError { one.Uid = uid one.Nick = nick one.Pwd = pwd one.Privilege = config.PrivilegePU err := userModel.Insert(one) if err != nil { uc.Error(err.Error(), 500) return } uc.W.Header().Add("Location", "/users/"+uid) uc.W.WriteHeader(201) } else { hint := valid.RenderErrMap() b, _ := json.Marshal(&hint) uc.W.WriteHeader(400) uc.W.Write(b) } }
func (this *UserController) Password(w http.ResponseWriter, r *http.Request) { class.Logger.Debug("User Password") this.Init(w, r) ok := 1 hint := make(map[string]string) hint["uid"] = this.Uid data := make(map[string]string) data["oldPassword"] = r.FormValue("user[oldPassword]") data["newPassword"] = r.FormValue("user[newPassword]") data["confirmPassword"] = r.FormValue("user[confirmPassword]") uid := this.Uid pwd := data["oldPassword"] userModel := model.UserModel{} ret, err := userModel.Login(uid, pwd) if err != nil { http.Error(w, err.Error(), 500) return } if ret.Uid == "" { ok, hint["oldPassword"] = 0, "Old Password is Incorrect." } if len(data["newPassword"]) < 6 { ok, hint["newPassword"] = 0, "Password should contain at least six characters." } if data["newPassword"] != data["confirmPassword"] { ok, hint["confirmPassword"] = 0, "Confirmation mismatched." } if ok == 1 { pwd = data["newPassword"] err := userModel.Password(uid, pwd) if err != nil { http.Error(w, err.Error(), 400) return } w.WriteHeader(200) } else { w.WriteHeader(400) } b, err := json.Marshal(&hint) if err != nil { http.Error(w, "json error", 400) return } w.Write(b) }
//@URL: /profile @method: GET func (uc *UserController) Edit() { restweb.Logger.Debug("User Edit") uid := uc.Uid userModel := model.UserModel{} one, err := userModel.Detail(uid) if err != nil { uc.Error(err.Error(), 400) return } uc.Output["Detail"] = one uc.Output["Title"] = "User Edit" uc.Output["IsSettings"] = true uc.Output["IsSettingsEdit"] = true uc.RenderTemplate("view/layout.tpl", "view/user_edit.tpl") }
//@URL: /users/(.+) @method: GET func (uc *UserController) Detail(uid string) { restweb.Logger.Debug("User Detail", uid) userModel := model.UserModel{} one, err := userModel.Detail(uid) if err != nil { uc.Error(err.Error(), 400) return } uc.Output["Detail"] = one solutionModle := model.SolutionModel{} solvedList, err := solutionModle.Achieve(uid, config.ModuleP, config.ModuleP) if err != nil { uc.Error(err.Error(), 400) return } type IPs struct { Time int64 IP string } var ips []IPs ipo := IPs{} for i, lenth := 0, len(one.IPRecord); i < lenth; i++ { ipo.Time = one.TimeRecord[i] ipo.IP = one.IPRecord[i] ips = append(ips, ipo) } achieveList := sort.IntSlice(solvedList) achieveList.Sort() uc.Output["List"] = achieveList uc.Output["IpList"] = ips uc.Output["Title"] = "User Detail" if uid != "" && uid == uc.Uid { uc.Output["IsSettings"] = true uc.Output["IsSettingsDetail"] = true } uc.RenderTemplate("view/layout.tpl", "view/user_detail.tpl") }
func (this *UserController) Settings(w http.ResponseWriter, r *http.Request) { class.Logger.Debug("User Settings") this.Init(w, r) if this.Privilege == config.PrivilegeNA { this.Data["Title"] = "Warning" this.Data["Info"] = "You must login!" err := this.Execute(w, "view/layout.tpl", "view/400.tpl") if err != nil { http.Error(w, "tpl error", 500) return } return } userModel := model.UserModel{} one, err := userModel.Detail(this.Uid) if err != nil { http.Error(w, err.Error(), 400) return } this.Data["Detail"] = one solutionModel := model.SolutionModel{} solvedList, err := solutionModel.Achieve(this.Uid) if err != nil { http.Error(w, err.Error(), 400) return } this.Data["List"] = solvedList this.Data["Title"] = "User Settings" this.Data["IsSettings"] = true this.Data["IsSettingsDetail"] = true err = this.Execute(w, "view/layout.tpl", "view/user_detail.tpl") if err != nil { http.Error(w, "tpl error", 500) return } }
//@URL: /account @method: POST func (uc *UserController) Password() { restweb.Logger.Debug("User Password") valid := restweb.Validation{} uid := uc.Uid // valid.AppendError("uid", uid) oldPwd := uc.Input.Get("user[oldPassword]") newPwd := uc.Input.Get("user[newPassword]") confirmPwd := uc.Input.Get("user[confirmPassword]") userModel := model.UserModel{} ret, err := userModel.Login(uid, oldPwd) if err != nil { uc.Error(err.Error(), 500) return } if ret.Uid == "" { valid.AppendError("oldPassword", "Old Password is Incorrect.") } valid.MinSize(newPwd, 6, "newPassword") valid.Equal(newPwd, confirmPwd, "confirmPassword") if !valid.HasError { err := userModel.Password(uid, newPwd) if err != nil { uc.Error(err.Error(), 400) return } uc.W.WriteHeader(200) } else { uc.W.WriteHeader(400) } hint := valid.RenderErrMap() b, _ := json.Marshal(&hint) uc.W.Write(b) }
func (this *solution) UpdateRecord() { if this.Module != config.ModuleP { return } solutionModel := model.SolutionModel{} qry := make(map[string]string) qry["module"] = strconv.Itoa(config.ModuleP) qry["action"] = "submit" qry["pid"] = strconv.Itoa(this.Pid) submit, _ := solutionModel.Count(qry) qry["action"] = "solve" solve, _ := solutionModel.Count(qry) proModel := model.ProblemModel{} err := proModel.Record(this.Pid, solve, submit) if err != nil { logger.Println(err) } qry["action"] = "submit" qry["uid"] = this.Uid delete(qry, "pid") delete(qry, "module") submit, _ = solutionModel.Count(qry) solvelist, err := solutionModel.Achieve(this.Uid, config.ModuleP, config.ModuleP) if err != nil { logger.Println(err) } solve = len(solvelist) userModel := model.UserModel{} err = userModel.Record(this.Uid, solve, submit) if err != nil { logger.Println(err) } }
func (this *UserController) Privilegeset(w http.ResponseWriter, r *http.Request) { class.Logger.Debug("User Privilege") this.Init(w, r) args := this.ParseURL(r.URL.String()) uid := args["uid"] privilegeStr := args["type"] privilege := config.PrivilegeNA switch privilegeStr { case "Admin": privilege = config.PrivilegeAD case "TC": privilege = config.PrivilegeTC case "PU": privilege = config.PrivilegePU default: http.Error(w, "args error", 400) } ok := 1 hint := make(map[string]string) if uid == "" { ok, hint["uid"] = 0, "Handle should not be empty." } else if uid == this.Uid { ok, hint["uid"] = 0, "You cannot delete yourself" } else { userModel := model.UserModel{} _, err := userModel.Detail(uid) if err == model.NotFoundErr { ok, hint["uid"] = 0, "This handle does not exist!" } else if err != nil { http.Error(w, err.Error(), 400) return } } if ok == 1 { userModel := model.UserModel{} err := userModel.Privilege(uid, privilege) if err != nil { http.Error(w, err.Error(), 400) return } w.WriteHeader(200) } else { b, err := json.Marshal(&hint) if err != nil { http.Error(w, "json error", 500) return } w.WriteHeader(400) w.Write(b) } }
func (this *UserController) Update(w http.ResponseWriter, r *http.Request) { class.Logger.Debug("User Update") this.Init(w, r) ok := 1 hint := make(map[string]string) hint["uid"] = this.Uid var one model.User one.Nick = r.FormValue("user[nick]") one.Mail = r.FormValue("user[mail]") one.School = r.FormValue("user[school]") one.Motto = r.FormValue("user[motto]") if one.Nick == "" { ok, hint["nick"] = 0, "Nick should not be empty." } if ok == 1 { userModel := model.UserModel{} err := userModel.Update(this.Uid, one) if err != nil { http.Error(w, err.Error(), 500) return } w.WriteHeader(200) } else { w.WriteHeader(400) } b, err := json.Marshal(&hint) if err != nil { http.Error(w, "json error", 400) return } w.Write(b) }
func (this *UserController) Login(w http.ResponseWriter, r *http.Request) { class.Logger.Debug("User Login") this.Init(w, r) uid := r.FormValue("user[handle]") pwd := r.FormValue("user[password]") userModel := model.UserModel{} ret, err := userModel.Login(uid, pwd) if err != nil { class.Logger.Debug(err) http.Error(w, err.Error(), 500) return } if ret.Uid == "" { w.WriteHeader(400) } else { this.SetSession(w, r, "Uid", uid) this.SetSession(w, r, "Privilege", strconv.Itoa(ret.Privilege)) w.WriteHeader(200) } return }
//显示具有特殊权限的用户 //@URL: /admin/users/ @method: GET func (uc *AdminUser) List() { restweb.Logger.Debug("Admin Privilege User List") if uc.Privilege != config.PrivilegeAD { restweb.Logger.Info(uc.Uid + " try to visit Admin page") uc.Output["Title"] = "Warning" uc.Output["Info"] = "You are not admin!" uc.RenderTemplate("view/layout.tpl", "view/400.tpl") return } userModel := model.UserModel{} userlist, err := userModel.List(nil) if err != nil { uc.Error(err.Error(), 500) return } uc.Output["User"] = userlist uc.Output["Title"] = "Privilege User List" uc.Output["IsUser"] = true uc.Output["IsList"] = true uc.RenderTemplate("view/admin/layout.tpl", "view/admin/user_list.tpl") }
func (this *UserController) Password(w http.ResponseWriter, r *http.Request) { class.Logger.Debug("Admin Password") this.Init(w, r) ok := 1 hint := make(map[string]string) data := make(map[string]string) data["userHandle"] = r.FormValue("user[Handle]") data["newPassword"] = r.FormValue("user[newPassword]") data["confirmPassword"] = r.FormValue("user[confirmPassword]") uid := r.FormValue("user[Handle]") if uid == "" { ok, hint["uid"] = 0, "Handle should not be empty" } else { userModel := model.UserModel{} _, err := userModel.Detail(uid) if err == model.NotFoundErr { ok, hint["uid"] = 0, "This handle does not exist!" } else if err != nil { http.Error(w, err.Error(), 400) return } } if len(data["newPassword"]) < 6 { ok, hint["newPassword"] = 0, "Password should contain at least six characters." } if data["newPassword"] != data["confirmPassword"] { ok, hint["confirmPassword"] = 0, "Confirmation mismatched." } if ok == 1 { pwd := data["newPassword"] userModel := model.UserModel{} err := userModel.Password(uid, pwd) if err != nil { http.Error(w, err.Error(), 400) return } w.WriteHeader(200) } else { w.WriteHeader(400) } b, err := json.Marshal(&hint) if err != nil { http.Error(w, "json error", 400) return } w.Write(b) }
// 设置用户权限 //@URL: /admin/privilegeset @method: POST func (uc *AdminUser) Privilegeset() { restweb.Logger.Debug("User Privilege") uid := uc.Input.Get("uid") privilegeStr := uc.Input.Get("type") privilege := config.PrivilegeNA switch privilegeStr { case "Admin": privilege = config.PrivilegeAD case "TC": privilege = config.PrivilegeTC case "PU": privilege = config.PrivilegePU default: uc.Error("args error", 400) } ok := 1 hint := make(map[string]string) if uid == "" { ok, hint["hint"] = 0, "Handle should not be empty." } else if uid == uc.Uid { ok, hint["hint"] = 0, "You cannot delete yourself!" } else { userModel := model.UserModel{} _, err := userModel.Detail(uid) if err == model.NotFoundErr { ok, hint["hint"] = 0, "uc handle does not exist!" } else if err != nil { uc.Error(err.Error(), 400) return } } if ok == 1 { userModel := model.UserModel{} err := userModel.Privilege(uid, privilege) if err != nil { uc.Error(err.Error(), 400) return } uc.W.WriteHeader(200) } else { b, _ := json.Marshal(&hint) uc.W.WriteHeader(400) uc.W.Write(b) } }
//设置用户密码 //@URL: /admin/users/password @method: PUT func (uc *AdminUser) Password() { restweb.Logger.Debug("Admin Password") ok := 1 hint := make(map[string]string) data := make(map[string]string) data["userHandle"] = uc.Input.Get("user[Handle]") data["newPassword"] = uc.Input.Get("user[newPassword]") data["confirmPassword"] = uc.Input.Get("user[confirmPassword]") uid := uc.Input.Get("user[Handle]") if uid == "" { ok, hint["uid"] = 0, "Handle should not be empty" } else { userModel := model.UserModel{} _, err := userModel.Detail(uid) if err == model.NotFoundErr { ok, hint["uid"] = 0, "uc handle does not exist!" } else if err != nil { uc.Error(err.Error(), 400) return } } if len(data["newPassword"]) < 6 { ok, hint["newPassword"] = 0, "Password should contain at least six characters." } if data["newPassword"] != data["confirmPassword"] { ok, hint["confirmPassword"] = 0, "Confirmation mismatched." } if ok == 1 { pwd := data["newPassword"] userModel := model.UserModel{} err := userModel.Password(uid, pwd) if err != nil { uc.Error(err.Error(), 400) return } uc.W.WriteHeader(200) } else { uc.W.WriteHeader(400) } b, _ := json.Marshal(&hint) uc.W.Write(b) }
func (this *UserController) Register(w http.ResponseWriter, r *http.Request) { class.Logger.Debug("User Register") this.Init(w, r) var one model.User userModel := model.UserModel{} uid := r.FormValue("user[handle]") nick := r.FormValue("user[nick]") pwd := r.FormValue("user[password]") pwdConfirm := r.FormValue("user[confirmPassword]") one.Mail = r.FormValue("user[mail]") one.School = r.FormValue("user[school]") one.Motto = r.FormValue("user[motto]") ok := 1 hint := make(map[string]string) if uid == "" { ok, hint["uid"] = 0, "Handle should not be empty." } else { qry := make(map[string]string) qry["uid"] = uid ret, err := userModel.List(qry) if err != nil { http.Error(w, err.Error(), 500) } else if len(ret) > 0 { ok, hint["uid"] = 0, "This handle is currently in use." } } if nick == "" { ok, hint["nick"] = 0, "Nick should not be empty." } if len(pwd) < 6 { ok, hint["pwd"] = 0, "Password should contain at least six characters." } if pwd != pwdConfirm { ok, hint["pwdConfirm"] = 0, "Confirmation mismatched." } if ok == 1 { one.Uid = uid one.Nick = nick one.Pwd = pwd //one.Privilege = config.PrivilegePU one.Privilege = config.PrivilegeAD err := userModel.Insert(one) if err != nil { http.Error(w, err.Error(), 500) return } this.SetSession(w, r, "Uid", uid) this.SetSession(w, r, "Privilege", "1") w.WriteHeader(200) } else { b, err := json.Marshal(&hint) if err != nil { http.Error(w, "json error", 500) return } w.WriteHeader(400) w.Write(b) } }
//提交某一问题的solution //@URL: /problems/(\d+) @method: POST func (pc *ProblemController) Submit(Pid string) { restweb.Logger.Debug("Problem Submit") pid, err := strconv.Atoi(Pid) if err != nil { pc.Error("args error", 400) return } var one model.Solution one.Pid = pid one.Uid = pc.Uid one.Module = config.ModuleP one.Mid = config.ModuleP // Todo use pid as mid problemModel := model.ProblemModel{} pro, err := problemModel.Detail(pid) if err != nil { pc.Error(err.Error(), 500) return } code := pc.Input.Get("code") one.Code = code one.Length = pc.GetCodeLen(len(pc.Input.Get("code"))) one.Language, _ = strconv.Atoi(pc.Input.Get("compiler_id")) pc.SetSession("Compiler_id", pc.Input.Get("compiler_id")) //or set cookie? userModel := model.UserModel{} user, _ := userModel.Detail(pc.Uid) one.Share = user.ShareCode hint := make(map[string]string) errflag := true switch { case pro.Pid == 0: hint["info"] = "No such problem." case code == "": hint["info"] = "Your source code is too short." default: errflag = false } if errflag { b, _ := json.Marshal(&hint) pc.W.WriteHeader(400) pc.W.Write(b) return } one.Status = config.StatusAvailable one.Judge = config.JudgePD solutionModel := model.SolutionModel{} sid, err := solutionModel.Insert(one) if err != nil { pc.Error(err.Error(), 500) return } pc.W.WriteHeader(201) go func() { //编译运行solution one := make(map[string]interface{}) one["Sid"] = sid one["Pid"] = pro.RPid one["OJ"] = pro.ROJ one["Rejudge"] = false reader, _ := pc.JsonReader(&one) restweb.Logger.Debug(reader) _, err := http.Post(config.JudgeHost, "application/json", reader) if err != nil { restweb.Logger.Debug("sid[", sid, "] submit post error") } }() }
//@URL: /ranklist @method: GET func (rc *RanklistController) Index() { restweb.Logger.Debug("Ranklist") // Page if _, ok := rc.Input["page"]; !ok { rc.Input.Set("page", "1") } userModel := model.UserModel{} userList, err := userModel.List(nil) if err != nil { http.Error(rc.W, err.Error(), 400) return } var count int count = 1 for _, one := range userList { if one.Status == config.StatusAvailable { count += 1 } } var pageCount = (count-1)/config.UserPerPage + 1 page, err := strconv.Atoi(rc.Input.Get("page")) if err != nil { rc.Error("args error", 400) return } if page > pageCount { rc.Error("args error", 400) return } pageData := rc.GetPage(page, pageCount) for k, v := range pageData { rc.Output[k] = v } qry := make(map[string]string) qry["offset"] = strconv.Itoa((page - 1) * config.UserPerPage) qry["limit"] = strconv.Itoa(config.UserPerPage) userList, err = userModel.List(qry) if err != nil { } list := make([]rank, len(userList), len(userList)) count = 1 for i, one := range userList { list[i].User = *one if one.Status == config.StatusAvailable { list[count-1].Index = count + (page-1)*config.UserPerPage count += 1 } } rc.Output["URL"] = "/ranklist?" rc.Output["User"] = list rc.Output["Title"] = "Ranklist" rc.Output["IsRanklist"] = true rc.RenderTemplate("view/layout.tpl", "view/ranklist.tpl") }
func (this *RanklistController) Index(w http.ResponseWriter, r *http.Request) { class.Logger.Debug("Ranklist") this.Init(w, r) args := this.ParseURL(r.URL.String()) this.Data["URL"] = "/ranklist" // Page if _, ok := args["page"]; !ok { args["page"] = "1" } userModel := model.UserModel{} userList, err := userModel.List(nil) if err != nil { http.Error(w, err.Error(), 400) return } var count int count = 1 for _, one := range userList { if one.Status == config.StatusAvailable { count += 1 } } var pageCount = (count-1)/config.UserPerPage + 1 page, err := strconv.Atoi(args["page"]) if err != nil { http.Error(w, "args error", 400) return } if page > pageCount { http.Error(w, "args error", 400) return } pageData := this.GetPage(page, pageCount) for k, v := range pageData { this.Data[k] = v } qry := make(map[string]string) qry["offset"] = strconv.Itoa((page - 1) * config.UserPerPage) qry["limit"] = strconv.Itoa(config.UserPerPage) userList, err = userModel.List(qry) if err != nil { } list := make([]rank, len(userList), len(userList)) count = 1 for i, one := range userList { list[i].User = *one if one.Status == config.StatusAvailable { list[count-1].Index = count count += 1 } } this.Data["User"] = list this.Data["Title"] = "Ranklist" this.Data["IsRanklist"] = true err = this.Execute(w, "view/layout.tpl", "view/ranklist.tpl") if err != nil { http.Error(w, "tpl error", 500) return } }