当前位置: 首页>>代码示例>>Golang>>正文


Golang webapp.Context类代码示例

本文整理汇总了Golang中github.com/salviati/tattoo/webapp.Context的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Context类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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)
		}
	}
}
开发者ID:salviati,项目名称:tattoo,代码行数:34,代码来源:serv.go

示例2: RenderWriterEditor

func RenderWriterEditor(ctx *webapp.Context, article *Article) error {
	vars := make(map[string]interface{})
	vars["Article"] = article
	data := MakeData(ctx, vars)
	data.Flags.WriterEditor = true
	err := ctx.Execute(editorTPL, &data)
	return err
}
开发者ID:salviati,项目名称:tattoo,代码行数:8,代码来源:render.go

示例3: RenderWriterSettings

func RenderWriterSettings(ctx *webapp.Context, msg string) error {
	vars := make(map[string]interface{})
	vars["Message"] = msg
	data := MakeData(ctx, vars)
	data.Flags.WriterSettings = true
	err := ctx.Execute(writerTPL, &data)
	return err
}
开发者ID:salviati,项目名称:tattoo,代码行数:8,代码来源:render.go

示例4: RenderSinglePage

func RenderSinglePage(ctx *webapp.Context, name string, lastMeta *CommentMetadata) error {
	vars := make(map[string]interface{})
	vars["Name"] = name
	vars["LastCommentMeta"] = lastMeta
	data := MakeData(ctx, vars)
	data.Flags.Single = true
	err := ctx.Execute(mainTPL, &data)
	return err
}
开发者ID:salviati,项目名称:tattoo,代码行数:9,代码来源:render.go

示例5: RenderFeedAtom

func RenderFeedAtom(ctx *webapp.Context) error {
	vars := make(map[string]interface{})
	vars["Declaration"] = template.HTML("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
	data := MakeData(ctx, vars)
	data.Flags.Feed = true
	ctx.SetHeader("Content-Type", "application/atom+xml")
	err := ctx.Execute(feedTPL, &data)
	return err
}
开发者ID:salviati,项目名称:tattoo,代码行数:9,代码来源:render.go

示例6: RenderGuard

func RenderGuard(ctx *webapp.Context, hint string) error {
	vars := make(map[string]interface{})
	vars["Error"] = ""
	if len(hint) != 0 {
		vars["Error"] = hint
	}
	data := MakeData(ctx, vars)
	err := ctx.Execute(guardTPL, &data)
	return err
}
开发者ID:salviati,项目名称:tattoo,代码行数:10,代码来源:render.go

示例7: HandleComment

func HandleComment(c *webapp.Context) {
	if c.Request.Method == "POST" {
		IP := strings.Split(c.Request.RemoteAddr, ":")[0]
		comment := new(Comment)
		comment.Metadata.Name = UUID()
		comment.Metadata.IP = IP
		comment.Metadata.CreatedTime = time.Now().Unix()
		comment.Metadata.Author = strings.Trim(c.Request.FormValue("author"), " ")
		comment.Metadata.ArticleName = strings.Trim(c.Request.FormValue("article_name"), " /")
		comment.Metadata.UAgent = strings.Trim(c.Request.UserAgent(), " ")
		comment.Metadata.Email = strings.Trim(c.Request.FormValue("email"), " ")
		comment.Metadata.URL = strings.Trim(c.Request.FormValue("url"), " ")
		if strings.Index(comment.Metadata.URL, "http://") == -1 && strings.Index(comment.Metadata.URL, "https://") == -1 {
			comment.Metadata.URL = "http://" + comment.Metadata.URL
		}
		comment.Text = template.HTML(strings.Trim(c.Request.FormValue("text"), " "))

		var cookie *http.Cookie

		expires := time.Date(2099, time.November, 10, 23, 0, 0, 0, time.UTC)
		cookie = new(http.Cookie)
		cookie.Path = "/"
		cookie.Expires = expires
		cookie.Name = "author"
		cookie.Value = comment.Metadata.Author
		http.SetCookie(c.Writer, cookie)
		cookie.Name = "email"
		cookie.Value = comment.Metadata.Email
		http.SetCookie(c.Writer, cookie)
		cookie.Name = "url"
		cookie.Value = comment.Metadata.URL
		http.SetCookie(c.Writer, cookie)

		// verify the form data
		if len(comment.Metadata.Author) == 0 || len(comment.Metadata.Email) < 3 || len(comment.Text) < 3 || len(comment.Metadata.Author) > 20 || len(comment.Metadata.Email) > 32 {
			c.Redirect("/"+comment.Metadata.ArticleName+"#respond", http.StatusFound)
			return
		}
		if !webapp.CheckEmailForm(comment.Metadata.Email) || (0 < len(comment.Metadata.URL) && !webapp.CheckURLForm(comment.Metadata.URL)) {
			c.Redirect("/"+comment.Metadata.ArticleName+"#respond", http.StatusFound)
			return
		}
		if !TattooDB.Has(comment.Metadata.ArticleName) {
			c.Redirect("/"+comment.Metadata.ArticleName+"#respond", http.StatusFound)
			return
		}
		comment.Text = template.HTML(webapp.TransformTags(string(comment.Text)))
		comment.Metadata.EmailHash = MD5Sum(comment.Metadata.Email)
		TattooDB.AddComment(comment)
		TattooDB.PrependCommentTimeline(comment)
		c.Redirect("/"+comment.Metadata.ArticleName+"#comment_"+comment.Metadata.Name, http.StatusFound)
	} else {
		c.Redirect("/"+c.Request.FormValue("article_name"), http.StatusFound)
	}
}
开发者ID:salviati,项目名称:tattoo,代码行数:55,代码来源:serv.go

示例8: HandleHome

func HandleHome(c *webapp.Context) {
	pos, _ := strconv.Atoi(c.Request.FormValue("pos"))
	if pos > TattooDB.GetArticleCount()-1 {
		c.Redirect("/", http.StatusFound)
		return
	}
	err := RenderHomePage(c, pos)
	if err != nil {
		c.Error(fmt.Sprintf("%s: %s", webapp.ErrInternalServerError, err), http.StatusInternalServerError)
	}
}
开发者ID:salviati,项目名称:tattoo,代码行数:11,代码来源:serv.go

示例9: HandleSinglePage

func HandleSinglePage(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)
	}
}
开发者ID:salviati,项目名称:tattoo,代码行数:16,代码来源:serv.go

示例10: 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
}
开发者ID:salviati,项目名称:tattoo,代码行数:16,代码来源:render.go

示例11: 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)
	}
}
开发者ID:salviati,项目名称:tattoo,代码行数:17,代码来源:serv.go

示例12: RenderHomePage

func RenderHomePage(ctx *webapp.Context, offset int) error {
	vars := make(map[string]interface{})
	vars["Offset"] = offset

	vars["AtBegin"] = false
	vars["AtEnd"] = false
	vars["Offset"] = offset
	if TattooDB.GetArticleCount()-1-offset < GetConfig().TimelineCount {
		vars["AtEnd"] = true
	}
	if offset < GetConfig().TimelineCount {
		vars["AtBegin"] = true
	}
	data := MakeData(ctx, vars)
	data.Flags.Home = true
	err := ctx.Execute(mainTPL, &data)
	return err
}
开发者ID:salviati,项目名称:tattoo,代码行数:18,代码来源:render.go

示例13: RenderWriterComments

func RenderWriterComments(ctx *webapp.Context, offset int) error {
	vars := make(map[string]interface{})
	vars["Offset"] = offset

	vars["AtBegin"] = false
	vars["AtEnd"] = false
	vars["Offset"] = offset
	if TattooDB.GetCommentCount()-1-offset < 20 {
		vars["AtEnd"] = true
	}
	if offset < 20 {
		vars["AtBegin"] = true
	}
	data := MakeData(ctx, vars)
	data.Flags.WriterComments = true
	err := ctx.Execute(writerTPL, &data)
	return err
}
开发者ID:salviati,项目名称:tattoo,代码行数:18,代码来源:render.go

示例14: HandleUpdateSystemSettings

func HandleUpdateSystemSettings(c *webapp.Context) {
	portStr := strings.Trim(c.Request.FormValue("port"), " ")
	certificate := strings.Trim(c.Request.FormValue("certificate"), " ")
	sitebase := strings.Trim(c.Request.FormValue("sitebase"), " ")
	siteurl := strings.Trim(c.Request.FormValue("siteurl"), " ")
	sitetitle := strings.Trim(c.Request.FormValue("sitetitle"), " ")
	sitesubtitle := strings.Trim(c.Request.FormValue("sitesubtitle"), " ")
	path := strings.Trim(c.Request.FormValue("path"), " ")
	author := strings.Trim(c.Request.FormValue("author"), " ")
	timelinecountStr := strings.Trim(c.Request.FormValue("timelinecount"), " ")
	theme := strings.Trim(c.Request.FormValue("theme"), " ")
	// verify
	port, err := strconv.Atoi(portStr)
	if err != nil {
		RenderWriterSettings(c, "Port should be a positive integer!")
		return
	}
	timelinecount, err := strconv.Atoi(timelinecountStr)
	if err != nil {
		RenderWriterSettings(c, "Timeline Count should be a positive integer!")
		return
	}
	if err := LoadTheme(c.Application, theme); err != nil {
		RenderWriterSettings(c, fmt.Sprintf("Failed to load theme '%v': %v", theme, err))
		return
	}
	var newConfig Config
	newConfig.Port = port
	newConfig.Certificate = certificate
	newConfig.SiteBase = sitebase
	newConfig.SiteURL = siteurl
	newConfig.SiteTitle = sitetitle
	newConfig.SiteSubTitle = sitesubtitle
	newConfig.Path = path
	newConfig.AuthorName = author
	newConfig.TimelineCount = timelinecount
	newConfig.ThemeName = theme
	cfg := GetConfig()
	cfg.Update(&newConfig)
	cfg.Save()
	c.Redirect("/writer/settings", http.StatusFound)
}
开发者ID:salviati,项目名称:tattoo,代码行数:42,代码来源:serv.go

示例15: 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
		}
	}
}
开发者ID:salviati,项目名称:tattoo,代码行数:21,代码来源:serv.go


注:本文中的github.com/salviati/tattoo/webapp.Context类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。