本文整理汇总了Golang中github.com/shellex/tattoo/webapp.Context.Error方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Error方法的具体用法?Golang Context.Error怎么用?Golang Context.Error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/shellex/tattoo/webapp.Context
的用法示例。
在下文中一共展示了Context.Error方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: HandleGuard
func HandleGuard(c *webapp.Context) {
var err error
action := c.Request.FormValue("action")
if action == "logout" {
RevokeSessionTokon()
c.Redirect("/guard", http.StatusFound)
return
}
if c.Request.Method == "POST" {
cert := c.Request.FormValue("certificate")
if len(cert) == 0 {
c.Redirect("/guard", http.StatusFound)
return
}
if SHA256Sum(cert) == GetConfig().Certificate {
cookie := new(http.Cookie)
cookie.Name = "token"
cookie.Path = "/"
cookie.Value = GenerateSessionToken()
http.SetCookie(c.Writer, cookie)
c.Redirect("/writer", http.StatusFound)
} else {
err = RenderGuard(c, "Your password is not correct")
if err != nil {
c.Error(fmt.Sprintf("%s: %s", webapp.ErrInternalServerError, err), http.StatusInternalServerError)
}
}
} else if c.Request.Method == "GET" {
err = RenderGuard(c, "")
if err != nil {
c.Error(fmt.Sprintf("%s: %s", webapp.ErrInternalServerError, err), http.StatusInternalServerError)
}
}
}
示例2: HandleArticles
func HandleArticles(c *webapp.Context) {
pos, _ := strconv.Atoi(c.Request.FormValue("pos"))
if pos > TattooDB.GetArticleCount()-1 {
if HasTemplate("HOME") {
c.Redirect("/post/", http.StatusFound)
} else {
c.Redirect("/", http.StatusFound)
}
return
}
err := RenderArticles(c, pos)
if err != nil {
c.Error(fmt.Sprintf("%s: %s", webapp.ErrInternalServerError, err), http.StatusInternalServerError)
}
}
示例3: Render404page
func Render404page(ctx *webapp.Context, msg string) error {
if notFoundTPL != nil {
vars := make(map[string]interface{})
vars["Message"] = msg
vars["URL"] = ctx.Request.RequestURI
vars["Referer"] = ctx.Request.Referer()
data := MakeData(ctx, vars)
err := ctx.Execute(notFoundTPL, &data)
return err
} else {
ctx.Error(fmt.Sprintf("%s: %s", webapp.ErrNotFound, msg),
http.StatusNotFound)
return nil
}
return nil
}
示例4: HandleSingle
func HandleSingle(c *webapp.Context, pagename string) {
if TattooDB.Has(pagename) {
lastMeta := GetLastCommentMetadata(c)
err := RenderSinglePage(c, pagename, lastMeta)
if err != nil {
c.Error(fmt.Sprintf("%s: %s", webapp.ErrInternalServerError, err), http.StatusInternalServerError)
}
meta, err := TattooDB.GetMetadata(pagename)
if err == nil {
meta.Hits += 1
TattooDB.UpdateMetadata(meta)
}
} else {
Render404page(c, NOT_FOUND_MESSAGE)
}
}
示例5: HandleTag
func HandleTag(c *webapp.Context, tag string) {
tag = strings.Trim(tag, " ")
if !TattooDB.HasTag(tag) {
Render404page(c, NOT_FOUND_MESSAGE)
}
pos, _ := strconv.Atoi(c.Request.FormValue("pos"))
if pos > TattooDB.GetTagArticleCount(tag)-1 {
c.Redirect("/", http.StatusFound)
return
}
err := RenderTagPage(c, pos, tag)
if err != nil {
c.Error(fmt.Sprintf("%s: %s",
webapp.ErrInternalServerError, err),
http.StatusInternalServerError)
}
}
示例6: HandleFeed
func HandleFeed(c *webapp.Context, pathLevels []string) {
if len(pathLevels) < 2 {
c.Redirect("/feed/atom", http.StatusFound)
return
}
if pathLevels[1] == "atom" {
var meta *ArticleMetadata
var err error
if len(TattooDB.ArticleTimeline) != 0 {
meta, err = TattooDB.GetMetadata(TattooDB.ArticleTimeline[0])
if err == nil {
TattooDB.SetVar("LastUpdatedTime", TimeRFC3339(meta.ModifiedTime))
}
}
err = RenderFeedAtom(c)
if err != nil {
c.Error(fmt.Sprintf("%s: %s", webapp.ErrInternalServerError, err), http.StatusInternalServerError)
return
}
}
}
示例7: HandleHome
func HandleHome(c *webapp.Context) {
err := RenderHome(c)
if err != nil {
c.Error(fmt.Sprintf("%s: %s", webapp.ErrInternalServerError, err), http.StatusInternalServerError)
}
}
示例8: HandleWriter
func HandleWriter(c *webapp.Context, pathLevels []string) {
if ok := isAuthorized(c); !ok {
c.Redirect("/guard", http.StatusFound)
return
}
if c.Request.Method == "GET" {
var err error
if len(pathLevels) < 2 {
c.Redirect("/writer/overview", http.StatusFound)
return
}
if pathLevels[1] == "overview" {
pos, _ := strconv.Atoi(c.Request.FormValue("pos"))
err = RenderWriterOverview(c, pos)
} else if pathLevels[1] == "pages" {
pos, _ := strconv.Atoi(c.Request.FormValue("pos"))
err = RenderWriterPages(c, pos)
} else if pathLevels[1] == "comments" {
pos, _ := strconv.Atoi(c.Request.FormValue("pos"))
if pos > TattooDB.GetCommentCount()-1 {
c.Redirect("/writer/comments", http.StatusFound)
return
}
err = RenderWriterComments(c, pos)
} else if pathLevels[1] == "settings" {
err = RenderWriterSettings(c, "")
} else if pathLevels[1] == "edit" {
var article *Article = new(Article)
var meta *ArticleMetadata = new(ArticleMetadata)
var source []byte
if len(pathLevels) >= 3 {
name := strings.ToLower(url.QueryEscape(pathLevels[2]))
meta, err = TattooDB.GetMetadata(name)
if err == nil {
source, err = TattooDB.GetArticleSource(name)
if err == nil {
article.Metadata = *meta
article.Text = template.HTML(string(source))
}
}
} else {
article = new(Article)
}
err = RenderWriterEditor(c, article)
} else if pathLevels[1] == "delete" {
if len(pathLevels) >= 3 {
name := strings.ToLower(url.QueryEscape(pathLevels[2]))
if TattooDB.Has(name) {
TattooDB.DeleteArticleTagIndex(name)
TattooDB.DeleteArticle(name)
TattooDB.DeleteMetadata(name)
TattooDB.DeleteComments(name)
TattooDB.Dump()
TattooDB.RebuildTimeline()
TattooDB.RebuildCommentTimeline()
}
}
c.Redirect("/writer", http.StatusFound)
} else if pathLevels[1] == "delete_comment" {
if len(pathLevels) >= 3 {
name := strings.ToLower(url.QueryEscape(pathLevels[2]))
if TattooDB.HasComment(name) {
TattooDB.DeleteComment(name)
TattooDB.RebuildCommentTimeline()
}
}
c.Redirect("/writer/comments", http.StatusFound)
} else {
Render404page(c, NOT_FOUND_MESSAGE)
}
if err != nil {
c.Error(fmt.Sprintf("%s: %s", webapp.ErrInternalServerError, err), http.StatusInternalServerError)
}
} else if c.Request.Method == "POST" {
if pathLevels[1] == "update" {
HandleUpdateArticle(c)
} else if pathLevels[1] == "settings" {
HandleUpdateSystemSettings(c)
} else {
c.Redirect("/writer", http.StatusFound)
return
}
}
}