當前位置: 首頁>>代碼示例>>Golang>>正文


Golang GoInk.Context類代碼示例

本文整理匯總了Golang中github.com/fuxiaohei/GoInk.Context的典型用法代碼示例。如果您正苦於以下問題:Golang Context類的具體用法?Golang Context怎麽用?Golang Context使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Context類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: CmdMonitor

func CmdMonitor(ctx *GoInk.Context) {
	ctx.Layout("admin/cmd")
	ctx.Render("admin/cmd/monitor", map[string]interface{}{
		"Title": "係統監控",
		"M":     cmd.ReadMemStats(),
	})
}
開發者ID:carriercomm,項目名稱:GoBlog,代碼行數:7,代碼來源:cmd.go

示例2: CmdMessage

func CmdMessage(context *GoInk.Context) {
	context.Layout("admin/cmd")
	context.Render("admin/cmd/message", map[string]interface{}{
		"Title":    "消息",
		"Messages": model.GetMessages(),
	})
}
開發者ID:carriercomm,項目名稱:GoBlog,代碼行數:7,代碼來源:cmd.go

示例3: Rss

func Rss(ctx *GoInk.Context) {
	baseUrl := model.GetSetting("site_url")
	article, _ := model.GetPublishArticleList(1, 20)
	author := model.GetUsersByRole("ADMIN")[0]

	articleMap := make([]map[string]string, len(article))
	for i, a := range article {
		m := make(map[string]string)
		m["Title"] = a.Title
		m["Link"] = strings.Replace(baseUrl+a.Link(), baseUrl+"/", baseUrl, -1)
		m["Author"] = author.Nick
		str := utils.Markdown2Html(a.Content())
		str = strings.Replace(str, `src="/`, `src="`+strings.TrimSuffix(baseUrl, "/")+"/", -1)
		str = strings.Replace(str, `href="/`, `href="`+strings.TrimSuffix(baseUrl, "/")+"/", -1)
		m["Desc"] = str
		m["Created"] = time.Unix(a.CreateTime, 0).Format(time.RFC822)
		articleMap[i] = m
	}

	ctx.ContentType("application/rss+xml;charset=UTF-8")

	bytes, e := ctx.App().View().Render("rss.xml", map[string]interface{}{
		"Title":    model.GetSetting("site_title"),
		"Link":     baseUrl,
		"Desc":     model.GetSetting("site_description"),
		"Created":  time.Unix(utils.Now(), 0).Format(time.RFC822),
		"Articles": articleMap,
	})
	if e != nil {
		panic(e)
	}
	ctx.Body = bytes
}
開發者ID:flying99999,項目名稱:GoBlog,代碼行數:33,代碼來源:rss.go

示例4: AdminProfile

func AdminProfile(context *GoInk.Context) {
	uid, _ := strconv.Atoi(context.Cookie("token-user"))
	user := model.GetUserById(uid)
	if context.Method == "POST" {
		data := context.Input()
		if !user.ChangeEmail(data["email"]) {
			Json(context, false).Set("msg", "郵箱與別的用戶重複").End()
			return
		}
		user.Name = data["user"]
		user.Email = data["email"]
		user.Avatar = utils.Gravatar(user.Email, "180")
		user.Url = data["url"]
		user.Nick = data["nick"]
		user.Bio = data["bio"]
		Json(context, true).End()
		go model.SyncUsers()
		go model.UpdateCommentAdmin(user)
		context.Do("profile_update", user)
		return
	}
	context.Layout("admin/admin")
	context.Render("admin/profile", map[string]interface{}{
		"Title": "個性資料",
		"User":  user,
	})
}
開發者ID:carriercomm,項目名稱:GoBlog,代碼行數:27,代碼來源:admin.go

示例5: ArticleWrite

func ArticleWrite(context *GoInk.Context) {
	if context.Method == "POST" {
		c := new(model.Content)
		c.Id = 0
		data := context.Input()
		if !c.ChangeSlug(data["slug"]) {
			Json(context, false).Set("msg", "固定鏈接重複").End()
			return
		}
		c.Title = data["title"]
		c.Text = data["content"]
		c.Tags = strings.Split(strings.Replace(data["tag"], ",", ",", -1), ",")
		c.IsComment = data["comment"] == "1"
		c.IsLinked = false
		c.AuthorId, _ = strconv.Atoi(context.Cookie("token-user"))
		c.Template = "blog.html"
		c.Status = data["status"]
		c.Format = "markdown"
		c.Hits = 1
		var e error
		c, e = model.CreateContent(c, "article")
		if e != nil {
			Json(context, false).Set("msg", e.Error()).End()
			return
		}
		Json(context, true).Set("content", c).End()
		context.Do("article_created", c)
		//c.Type = "article"
		return
	}
	context.Layout("admin/admin")
	context.Render("admin/write_article", map[string]interface{}{
		"Title": "撰寫文章",
	})
}
開發者ID:carriercomm,項目名稱:GoBlog,代碼行數:35,代碼來源:admin.go

示例6: SetThemeCache

func SetThemeCache(ctx *GoInk.Context, cache bool) {
	ctx.App().View().NoCache()
	ctx.App().View().IsCache = cache
	if cache {
		model.SetSetting("theme_cache", "true")
	} else {
		model.SetSetting("theme_cache", "false")
	}
	model.SyncSettings()
}
開發者ID:flying99999,項目名稱:GoBlog,代碼行數:10,代碼來源:theme.go

示例7: NavigatorSetting

func NavigatorSetting(context *GoInk.Context) {
	order := context.Strings("order")
	text := context.Strings("text")
	title := context.Strings("title")
	link := context.Strings("link")
	model.SetNavigators(order, text, title, link)
	Json(context, true).End()
	context.Do("setting_saved")
	return
}
開發者ID:carriercomm,項目名稱:GoBlog,代碼行數:10,代碼來源:admin.go

示例8: CmdLogs

func CmdLogs(context *GoInk.Context) {
	if context.Method == "DELETE" {
		cmd.RemoveLogFile(context.App(), context.String("file"))
		Json(context, true).End()
		return
	}
	context.Layout("admin/cmd")
	context.Render("admin/cmd/log", map[string]interface{}{
		"Title": "日誌",
		"Logs":  cmd.GetLogs(context.App()),
	})
}
開發者ID:carriercomm,項目名稱:GoBlog,代碼行數:12,代碼來源:cmd.go

示例9: Home

func Home(context *GoInk.Context) {
	context.Layout("home")
	page, _ := strconv.Atoi(context.Param("page"))
	articles, pager := model.GetPublishArticleList(page, getArticleListSize())
	data := map[string]interface{}{
		"Articles":    articles,
		"Pager":       pager,
		"SidebarHtml": SidebarHtml(context),
	}
	if page > 1 {
		data["Title"] = "第 " + strconv.Itoa(page) + " 頁"
	}
	Theme(context).Layout("home").Render("index", data)
}
開發者ID:carriercomm,項目名稱:GoBlog,代碼行數:14,代碼來源:home.go

示例10: Auth

func Auth(context *GoInk.Context) {
	tokenValue := context.Cookie("token-value")
	token := model.GetTokenByValue(tokenValue)
	if token == nil {
		context.Redirect("/logout/")
		context.End()
		return
	}
	if !token.IsValid() {
		context.Redirect("/logout/")
		context.End()
		return
	}
}
開發者ID:carriercomm,項目名稱:GoBlog,代碼行數:14,代碼來源:home.go

示例11: AdminMessageRead

func AdminMessageRead(context *GoInk.Context) {
	id := context.Int("id")
	if id < 0 {
		Json(context, false).End()
		return
	}
	m := model.GetMessage(id)
	if m == nil {
		Json(context, false).End()
		return
	}
	model.SaveMessageRead(m)
	Json(context, true).End()
}
開發者ID:carriercomm,項目名稱:GoBlog,代碼行數:14,代碼來源:admin.go

示例12: AdminFiles

func AdminFiles(context *GoInk.Context) {
	if context.Method == "DELETE" {
		id := context.Int("id")
		model.RemoveFile(id)
		Json(context, true).End()
		context.Do("attach_delete", id)
		return
	}
	files, pager := model.GetFileList(context.Int("page"), 10)
	context.Layout("admin/admin")
	context.Render("admin/files", map[string]interface{}{
		"Title": "媒體文件",
		"Files": files,
		"Pager": pager,
	})
}
開發者ID:flying99999,項目名稱:GoBlog,代碼行數:16,代碼來源:upload.go

示例13: SiteMap

func SiteMap(ctx *GoInk.Context) {
	baseUrl := model.GetSetting("site_url")
	println(baseUrl)
	article, _ := model.GetPublishArticleList(1, 50)
	navigators := model.GetNavigators()
	now := time.Unix(utils.Now(), 0).Format(time.RFC3339)

	articleMap := make([]map[string]string, len(article))
	for i, a := range article {
		m := make(map[string]string)
		m["Link"] = strings.Replace(baseUrl+a.Link(), baseUrl+"/", baseUrl, -1)
		m["Created"] = time.Unix(a.CreateTime, 0).Format(time.RFC3339)
		articleMap[i] = m
	}

	navMap := make([]map[string]string, 0)
	for _, n := range navigators {
		m := make(map[string]string)
		if n.Link == "/" {
			continue
		}
		if strings.HasPrefix(n.Link, "/") {
			m["Link"] = strings.Replace(baseUrl+n.Link, baseUrl+"/", baseUrl, -1)
		} else {
			m["Link"] = n.Link
		}
		m["Created"] = now
		navMap = append(navMap, m)
	}

	ctx.ContentType("text/xml")
	bytes, e := ctx.App().View().Render("sitemap.xml", map[string]interface{}{
		"Title":      model.GetSetting("site_title"),
		"Link":       baseUrl,
		"Created":    now,
		"Articles":   articleMap,
		"Navigators": navMap,
	})
	if e != nil {
		panic(e)
	}
	ctx.Body = bytes

}
開發者ID:flying99999,項目名稱:GoBlog,代碼行數:44,代碼來源:rss.go

示例14: Comment

func Comment(context *GoInk.Context) {
	cid, _ := strconv.Atoi(context.Param("id"))
	if cid < 1 {
		Json(context, false).End()
		return
	}
	if model.GetContentById(cid) == nil {
		Json(context, false).End()
		return
	}
	data := context.Input()
	msg := validateComment(data)
	if msg != "" {
		Json(context, false).Set("msg", msg).End()
		return
	}
	co := new(model.Comment)
	co.Author = data["user"]
	co.Email = data["email"]
	co.Url = data["url"]
	co.Content = data["content"]
	co.Avatar = utils.Gravatar(co.Email, "50")
	co.Pid, _ = strconv.Atoi(data["pid"])
	co.Ip = context.Ip
	co.UserAgent = context.UserAgent
	co.IsAdmin = false
	model.CreateComment(cid, co)
	Json(context, true).Set("comment", co.ToJson()).End()
	model.CreateMessage("comment", co)
	context.Do("comment_created", co)
}
開發者ID:carriercomm,項目名稱:GoBlog,代碼行數:31,代碼來源:home.go

示例15: AdminArticle

func AdminArticle(context *GoInk.Context) {
	articles, pager := model.GetArticleList(context.Int("page"), 10)
	context.Layout("admin/admin")
	context.Render("admin/articles", map[string]interface{}{
		"Title":    "文章",
		"Articles": articles,
		"Pager":    pager,
	})
}
開發者ID:carriercomm,項目名稱:GoBlog,代碼行數:9,代碼來源:admin.go


注:本文中的github.com/fuxiaohei/GoInk.Context類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。