本文整理匯總了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, "")
}