func ModifyAuthorityHandler(rw http.ResponseWriter, req *http.Request) { var data = make(map[string]interface{}) if req.PostFormValue("submit") == "1" { user, _ := filter.CurrentUser(req) username := user["username"].(string) errMsg, err := service.SaveAuthority(req.PostForm, username) if err != nil { data["ok"] = 0 data["error"] = errMsg } else { data["ok"] = 1 data["msg"] = "修改成功" } } else { menu1, menu2 := service.GetMenus() allmenu2, _ := json.Marshal(menu2) authority := service.FindAuthority(req.FormValue("aid")) if authority == nil || authority.Aid == 0 { rw.WriteHeader(http.StatusInternalServerError) return } // 设置内容模板 req.Form.Set(filter.CONTENT_TPL_KEY, "/template/admin/authority/modify.html") data["allmenu1"] = menu1 data["allmenu2"] = string(allmenu2) data["authority"] = authority } filter.SetData(req, data) }
func NewAuthorityHandler(rw http.ResponseWriter, req *http.Request) { var data = make(map[string]interface{}) if req.PostFormValue("submit") == "1" { user, _ := filter.CurrentUser(req) username := user["username"].(string) errMsg, err := service.SaveAuthority(req.PostForm, username) if err != nil { data["ok"] = 0 data["error"] = errMsg } else { data["ok"] = 1 data["msg"] = "添加成功" } } else { menu1, menu2 := service.GetMenus() allmenu2, _ := json.Marshal(menu2) // 设置内容模板 req.Form.Set(filter.CONTENT_TPL_KEY, "/template/admin/authority/new.html") data["allmenu1"] = menu1 data["allmenu2"] = string(allmenu2) } filter.SetData(req, data) }