本文整理汇总了Golang中github.com/speedland/wcg.Response.RenderInternalError方法的典型用法代码示例。如果您正苦于以下问题:Golang Response.RenderInternalError方法的具体用法?Golang Response.RenderInternalError怎么用?Golang Response.RenderInternalError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/speedland/wcg.Response
的用法示例。
在下文中一共展示了Response.RenderInternalError方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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
}
示例4: createPostHandler
func createPostHandler(res *wcg.Response, req *wcg.Request) {
blog, _, err := fetchBlogForUpdate(res, req, false)
if err != nil {
return
}
post := models.NewPost(req.User.Id(), blog.Id)
err = models.NewPostDriver(gae.NewContext(req), req.Logger).SavePost(post)
if err != nil {
res.RenderInternalError(err.Error())
return
}
res.Redirect(fmt.Sprintf("/admin/blogs/%s/%s/", blog.Id, post.Id), http.StatusSeeOther)
}
示例5: deleteBlogHandler
func deleteBlogHandler(res *wcg.Response, req *wcg.Request) {
driver := models.NewBlogDriver(gae.NewContext(req), req.Logger)
err := driver.DeleteBlog(req.Param("blog_id"), req.User.Id())
if err != nil {
if supports.IsValidationError(err) {
res.WriteJsonWithStatus(400, nil, err)
} else if err == models.ErrBlogNotOwned {
res.WriteJsonWithStatus(403, nil, no_permission)
} else if err == models.ErrBlogNotFound {
res.WriteJsonWithStatus(404, nil, not_found)
} else {
res.RenderInternalError(err.Error())
}
return
}
res.WriteJsonWithStatus(200, nil, ok)
}
示例6: deletePostHandler
func deletePostHandler(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
}
err = models.NewPostDriver(gae.NewContext(req), req.Logger).DeletePost(post)
if err != nil {
if supports.IsValidationError(err) {
res.WriteJsonWithStatus(400, nil, err)
} else {
res.RenderInternalError(err.Error())
}
return
}
res.WriteJsonWithStatus(200, nil, ok)
}
示例7: 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)
}
示例8: createBlogHandler
func createBlogHandler(res *wcg.Response, req *wcg.Request) {
driver := models.NewBlogDriver(gae.NewContext(req), req.Logger)
blog, err := driver.CreateBlog(
req.Form("path"),
req.Form("title"),
req.Form("description"),
req.User.Id(),
)
if err != nil {
if err == models.ErrBlogAlreadyExists {
res.WriteJsonWithStatus(409, nil, already_taken)
} else if supports.IsValidationError(err) {
res.WriteJsonWithStatus(400, nil, err)
} else {
res.RenderInternalError(err.Error())
}
return
}
res.WriteJsonWithStatus(201, map[string]string{
"location": wcg.AbsoluteUrl(req, "/"+blog.Id),
}, ok)
}