// get: /user/location/america func (uc *UserController) Location(ctx *wk.HttpContext) (result wk.HttpResult, err error) { location, ok := ctx.RouteData.Str("arg") if ok { users := userRepo.GetByLocation(location) ctx.ViewData["users"] = users } return wk.View("user/location.html"), nil }
// get: /user/edit/1 func (uc *UserController) EditGet(ctx *wk.HttpContext) (result wk.HttpResult, err error) { var id int if id, err = parseId(ctx); err != nil { return } if user, ok := userRepo.Get(id); ok { ctx.ViewData["user"] = user } return wk.View("user/edit.html"), nil }
func FileUpload(ctx *wk.HttpContext) (result wk.HttpResult, err error) { ctx.Request.ParseMultipartForm(32 << 20) // 32 MB b := &bytes.Buffer{} b.WriteString("files uploaded:\n") for _, headers := range ctx.Request.MultipartForm.File { for _, header := range headers { info := fileInfo(header) b.WriteString(fmt.Sprintf("Name: %s; Content-Type: %s; Size: %d \n", info.Name, info.Type, info.Size)) } } ctx.ViewData["msg"] = b.String() return wk.View("share/message.html"), nil }
// post: /user/edit/1 func (uc *UserController) EditPost(ctx *wk.HttpContext) (result wk.HttpResult, err error) { var id int if id, err = parseId(ctx); err != nil { return } u := User{ Id: id, Location: ctx.FV("location"), Gender: ctx.FV("gender"), Skills: ctx.Request.Form["skill"], } if userRepo.Update(u) { return wk.Redirect(fmt.Sprintf("/user/view/%d", id), false), nil } return wk.View("user/edit.html"), nil }
// get/post: /user/add func (uc *UserController) AddPost(ctx *wk.HttpContext) (result wk.HttpResult, err error) { id := 0 if name := ctx.FV("name"); name == "" { ctx.ViewData["errmsg"] = "name is required" } else if name == "error" { ctx.ViewData["errmsg"] = "name is error" } else if userRepo.Exists(name) { ctx.ViewData["errmsg"] = "name exists" } else { u := User{ Name: ctx.FV("name"), Location: ctx.FV("location"), Gender: ctx.FV("gender"), Skills: ctx.Request.Form["skill"], } id = userRepo.Add(u) } if id <= 0 { ctx.ViewData["ctx"] = ctx return wk.View("user/add.html"), nil } return wk.Redirect(fmt.Sprintf("/user/view/%d", id), false), nil }
// get: /doc/basicdemo func (uc *DocController) BasicDemo(ctx *wk.HttpContext) (result wk.HttpResult, err error) { return wk.View("doc/basic_demo.html"), nil }
// get: /doc/otherdemo func (uc *DocController) OtherDemo(ctx *wk.HttpContext) (result wk.HttpResult, err error) { return wk.View("doc/other_demo.html"), nil }
// get: /doc/configdemo func (uc *DocController) ConfigDemo(ctx *wk.HttpContext) (result wk.HttpResult, err error) { return wk.View("doc/config_demo.html"), nil }
// get: /doc/sessiondemo func (uc *DocController) SessionDemo(ctx *wk.HttpContext) (result wk.HttpResult, err error) { return wk.View("doc/session_demo.html"), nil }
// get: /doc/document func (uc *DocController) Document(ctx *wk.HttpContext) (result wk.HttpResult, err error) { return wk.View("doc/document.html"), nil }
// get: /doc/index func (uc *DocController) Index(ctx *wk.HttpContext) (result wk.HttpResult, err error) { return wk.View("doc/index.html"), nil }
// get: /user/all/ func (uc *UserController) All(ctx *wk.HttpContext) (result wk.HttpResult, err error) { ctx.ViewData["users"] = userRepo.All() return wk.View("user/_list.html"), nil }
func HomeAbout(ctx *wk.HttpContext) (result wk.HttpResult, err error) { return wk.View("doc/about.html"), nil }
func HomeIndex(ctx *wk.HttpContext) (result wk.HttpResult, err error) { return wk.View("doc/home.html"), nil }
// get: /user/add/ func (uc *UserController) AddGet(ctx *wk.HttpContext) (result wk.HttpResult, err error) { return wk.View("user/add.html"), nil }
// get: /doc/routedemo func (uc *DocController) RouteDemo(ctx *wk.HttpContext) (result wk.HttpResult, err error) { return wk.View("doc/route_demo.html"), nil }
// get: /doc/home func (uc *DocController) Home(ctx *wk.HttpContext) (result wk.HttpResult, err error) { return wk.View("doc/home.html"), nil }
func FileUploadView(ctx *wk.HttpContext) (result wk.HttpResult, err error) { return wk.View("doc/upload_demo.html"), nil }