本文整理汇总了Golang中code/minty/io/wombat.Context.FormValue方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.FormValue方法的具体用法?Golang Context.FormValue怎么用?Golang Context.FormValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类code/minty/io/wombat.Context
的用法示例。
在下文中一共展示了Context.FormValue方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: PostArticles
func (h Handler) PostArticles(ctx wombat.Context) {
title := ctx.FormValue("title")
if request.IsApplicationJson(ctx.Request) {
ctx.Response.Header().Set("Content-Type", "application/json")
defer ctx.Body.Close()
if b, err := ioutil.ReadAll(ctx.Body); err != nil {
m := make(map[string]interface{})
json.Unmarshal(b, &m)
title, _ = m["title"].(string)
}
}
if title == "" {
// Missing title
ctx.HttpError(http.StatusBadRequest, GetErrorStr(ctx.Request, "Missing title"))
return
}
t, err := CreateArticle(ctx, title)
if err != nil {
ctx.HttpError(http.StatusInternalServerError, GetError(ctx.Request, err))
return
}
// When not a JSON request issue redirect to new article
if !request.IsApplicationJson(ctx.Request) {
ctx.Redirect(fmt.Sprintf("%s/%s?view=edit", h.BasePath, t))
}
}
示例2: ImagesHandler
func ImagesHandler(ctx wombat.Context, a *articles.Article, imagePath string) {
// Get the name of the image, or random name if missing/empty
filename := ctx.FormValue("name")
if filename == "" {
filename = web.RandName(5)
}
// Save the thumbnail, or image
path := filepath.Join(imagePath, a.TitlePath)
if t := ctx.FormValue("type"); t == "thumb" {
ThumbHandler(ctx, a, path, "thumb."+filename)
} else {
ImageHandler(ctx, a, path, filename)
}
}
示例3: GetArticle
/*----------Article-----------*/
func (h Handler) GetArticle(ctx wombat.Context, titlePath string) {
isAdmin := ctx.User.IsAdmin()
o, ok := h.Article(titlePath, isAdmin)
if !ok {
ctx.HttpError(http.StatusNotFound)
return
}
tmpl := "view"
if isAdmin && ctx.FormValue("view") == "edit" {
tmpl = "edit"
}
// Handle HTTP/JSON response
articleResponse(ctx, &h, o, tmpl, titlePath)
}
示例4: GetArticles
/*----------Articles----------*/
func (h Handler) GetArticles(ctx wombat.Context) {
var tmpl string
var o interface{}
switch view := ctx.FormValue("view"); {
default:
tmpl = "list"
page, err := strconv.Atoi(ctx.FormValue("page"))
if err != nil {
page = 0
}
o, _ = h.articles.Recent(h.PageCount, page, ctx.User.IsAdmin())
case view == "create" && ctx.User.IsAdmin():
tmpl = "create"
}
// Handle HTTP/JSON response
articleResponse(ctx, &h, o, tmpl, "")
}