本文整理汇总了Golang中github.com/speedland/wcg.Response.WriteHeader方法的典型用法代码示例。如果您正苦于以下问题:Golang Response.WriteHeader方法的具体用法?Golang Response.WriteHeader怎么用?Golang Response.WriteHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/speedland/wcg.Response
的用法示例。
在下文中一共展示了Response.WriteHeader方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: fetchBlog
func fetchBlog(res *wcg.Response, req *wcg.Request, includePosts bool) (*models.Blog, *supports.Page, error) {
// default query for posts.
id := req.Param("blog_id")
driver := models.NewBlogDriver(gae.NewContext(req), req.Logger)
blog, query, err := driver.PostQuery(id)
if err != nil {
if err == models.ErrBlogNotFound {
res.WriteHeader(404)
res.WriteString("Not found")
res.End()
return nil, nil, err
}
res.RenderInternalError(err.Error())
return nil, nil, err
}
if !includePosts {
return blog, supports.EmptyPage, nil
}
query = query.Filter("IsNew =", false).Filter("IsDraft =", false).Order("-PostDate").Order("-UpdatedAt")
per_page := wcg.ParseInt(req.Query("num"), AppConfig.DefaultPostsFetched, 0, AppConfig.MaxPostsFetched)
current := wcg.ParseInt(req.Query("p"), 0, 0, wcg.ParseIntMax)
page, err := supports.NewPage(current, per_page, query)
if err != nil {
res.RenderInternalError("Post pagination error: %v", err)
return nil, nil, err
}
return blog, page, nil
}
示例2: fetchPost
func fetchPost(res *wcg.Response, req *wcg.Request, blog *models.Blog) (*models.Post, error) {
driver := models.NewPostDriver(gae.NewContext(req), req.Logger)
id := req.Param("post_id")
blogId := req.Param("blog_id")
post, err := driver.FindPostById(id, blogId)
if err != nil {
if err == models.ErrPostNotFound {
res.WriteHeader(404)
res.WriteString("Not found")
res.End()
return nil, err
}
res.RenderInternalError(err.Error())
return nil, err
}
if post.PostState() != models.PostStatePublished {
if post.OwnerId != req.User.Id() {
res.WriteHeader(404)
res.WriteString("Not found")
res.End()
return nil, err
}
}
return post, err
}
示例3: updatePostHandler
func updatePostHandler(res *wcg.Response, req *wcg.Request) {
blog, _, err := fetchBlogForUpdate(res, req, false)
if err != nil {
return
}
post, err := fetchPostForUpdate(req, res, blog)
if err != nil {
return
}
post.Title = req.Form("title")
post.Content = req.Form("content")
post.IsDraft = req.Form("is_draft") == "true"
post.IsNew = false
post.PostDate, err = time.Parse(wcg.FormDateFormat, req.Form("post_date"))
post.Tags = strings.Split(req.Form("tags"), ",")
for i, v := range post.Tags {
post.Tags[i] = strings.TrimSpace(v)
}
if err != nil {
res.WriteHeader(400)
res.WriteString("Invalid date format.")
res.End()
}
driver := models.NewPostDriver(gae.NewContext(req), req.Logger)
if AppConfig.GithubMarkdown {
driver.HttpClient = gae.NewHttpClient(req)
}
err = driver.SavePost(post)
if err != nil {
if supports.IsValidationError(err) {
res.WriteJsonWithStatus(400, nil, err)
} else {
res.RenderInternalError(err.Error())
}
return
}
req.Logger.Info("A post is created at %s.", post.Id)
res.WriteJsonWithStatus(200, nil, ok)
}
示例4: fetchPostForUpdate
func fetchPostForUpdate(req *wcg.Request, res *wcg.Response, blog *models.Blog) (*models.Post, error) {
driver := models.NewPostDriver(gae.NewContext(req), req.Logger)
id := req.Param("post_id")
blogId := req.Param("blog_id")
post, err := driver.FindPostById(id, blogId)
if err != nil {
if err == models.ErrPostNotFound {
res.WriteHeader(404)
res.WriteString("Not found")
res.End()
return nil, err
}
res.RenderInternalError(err.Error())
return nil, err
}
if blog.Id != post.BlogId {
res.WriteHeader(403)
res.WriteString("You could not manage that blog.")
res.End()
}
if post.OwnerId != req.User.Id() {
res.WriteHeader(403)
res.WriteString("You could not manage this post.")
res.End()
return nil, err
}
return post, err
}