本文整理汇总了Golang中github.com/fuxiaohei/GoBlog/GoInk.Context类的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Context类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Feed
func Feed(context *GoInk.Context) {
baseUrl := model.GetSetting("site_url")
article, _ := model.GetArticleList(1, 20)
feed := new(feeds.Feed)
feed.Title = model.GetSetting("site_title")
feed.Link = &feeds.Link{Href: baseUrl}
feed.Description = model.GetSetting("site_description")
author := model.GetUsersByRole("ADMIN")[0]
feed.Author = &feeds.Author{author.Nick, author.Email}
feed.Items = make([]*feeds.Item, 0)
var create int64
if len(article) > 0 {
create = article[0].EditTime
} else {
create = utils.Now()
}
feed.Created = time.Unix(create, 0)
for _, a := range article {
item := new(feeds.Item)
item.Title = a.Title
item.Link = &feeds.Link{Href: path.Join(baseUrl, a.Link())}
item.Author = feed.Author
item.Created = time.Unix(a.CreateTime, 0)
item.Description = utils.Html2str(a.Summary())
feed.Items = append(feed.Items, item)
}
str, e := feed.ToRss()
if e != nil {
panic(e)
}
context.ContentType("application/rss+xml;charset=UTF-8")
context.Body = []byte(str)
}
开发者ID:WytheOnly,项目名称:GoBlog,代码行数:33,代码来源:rss.go
示例2: 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()
return
}
context.Layout("admin")
context.Render("admin/profile", map[string]interface{}{
"Title": "个性资料",
"User": user,
})
}
开发者ID:WytheOnly,项目名称:GoBlog,代码行数:25,代码来源:admin.go
示例3: CmdBackup
func CmdBackup(context *GoInk.Context) {
if context.Method == "POST" {
file, e := cmd.DoBackup(context.App())
if e != nil {
Json(context, false).Set("msg", e.Error()).End()
return
}
Json(context, true).Set("file", file).End()
return
}
if context.Method == "DELETE" {
file := context.String("file")
if file == "" {
Json(context, false).End()
return
}
cmd.RemoveBackupFile(file)
Json(context, true).End()
return
}
files, _ := cmd.GetBackupFiles()
context.Layout("cmd")
context.Render("cmd/backup", map[string]interface{}{
"Files": files,
})
}
开发者ID:WytheOnly,项目名称:GoBlog,代码行数:26,代码来源:cmd.go
示例4: 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:WytheOnly,项目名称:GoBlog,代码行数:14,代码来源:home.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()
//c.Type = "article"
return
}
context.Layout("admin")
context.Render("admin/write_article", map[string]interface{}{
"Title": "撰写文章",
})
}
开发者ID:WytheOnly,项目名称:GoBlog,代码行数:34,代码来源:admin.go
示例6: TopPage
func TopPage(context *GoInk.Context) {
slug := context.Param("slug")
page := model.GetContentBySlug(slug)
if page == nil {
context.Redirect("/")
return
}
if page.IsLinked && page.Type == "page" {
context.Layout("home")
context.Render("home/page", map[string]interface{}{
"Title": page.Title,
"Page": page,
})
page.Hits++
return
}
context.Redirect("/")
}
开发者ID:WytheOnly,项目名称:GoBlog,代码行数:18,代码来源:home.go
示例7: AdminPassword
func AdminPassword(context *GoInk.Context) {
if context.Method == "POST" {
uid, _ := strconv.Atoi(context.Cookie("token-user"))
user := model.GetUserById(uid)
if !user.CheckPassword(context.String("old")) {
Json(context, false).Set("msg", "旧密码错误").End()
return
}
user.ChangePassword(context.String("new"))
go model.SyncUsers()
Json(context, true).End()
return
}
context.Layout("admin")
context.Render("admin/password", map[string]interface{}{
"Title": "修改密码",
//"User":user,
})
}
开发者ID:WytheOnly,项目名称:GoBlog,代码行数:19,代码来源:admin.go
示例8: FileUpload
func FileUpload(context *GoInk.Context) {
var req *http.Request
req = context.Request
req.ParseMultipartForm(32 << 20)
f, h, e := req.FormFile("file")
if e != nil {
Json(context, false).Set("msg", e.Error()).End()
return
}
data, _ := ioutil.ReadAll(f)
maxSize := context.App().Config().IntOr("app.upload_size", 1024*1024*10)
defer func() {
f.Close()
data = nil
h = nil
}()
if len(data) >= maxSize {
Json(context, false).Set("msg", "文件应小于10M").End()
return
}
if !strings.Contains(context.App().Config().String("app.upload_files"), path.Ext(h.Filename)) {
Json(context, false).Set("msg", "文件只支持Office文件,图片和zip存档").End()
return
}
ff := new(model.File)
ff.Name = h.Filename
ff.Type = context.StringOr("type", "image")
ff.Size = int64(len(data))
ff.ContentType = h.Header["Content-Type"][0]
ff.Author, _ = strconv.Atoi(context.Cookie("token-user"))
ff.Url = model.CreateFilePath(context.App().Get("upload_dir"), ff)
e = ioutil.WriteFile(ff.Url, data, os.ModePerm)
if e != nil {
Json(context, false).Set("msg", e.Error()).End()
return
}
model.CreateFile(ff)
Json(context, true).Set("file", ff).End()
}
开发者ID:WytheOnly,项目名称:GoBlog,代码行数:39,代码来源:upload.go
示例9: AdminFiles
func AdminFiles(context *GoInk.Context) {
if context.Method == "DELETE" {
id := context.Int("id")
model.RemoveFile(id)
Json(context, true).End()
return
}
files, pager := model.GetFileList(context.Int("page"), 10)
context.Layout("admin")
context.Render("admin/files", map[string]interface{}{
"Title": "媒体文件",
"Files": files,
"Pager": pager,
})
}
开发者ID:WytheOnly,项目名称:GoBlog,代码行数:15,代码来源:upload.go
示例10: PageEdit
func PageEdit(context *GoInk.Context) {
id, _ := strconv.Atoi(context.Param("id"))
c := model.GetContentById(id)
if c == nil {
context.Redirect("/admin/pages/")
return
}
if context.Method == "DELETE" {
model.RemoveContent(c)
Json(context, true).End()
return
}
if context.Method == "POST" {
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 = data["link"] == "1"
//c.AuthorId, _ = strconv.Atoi(context.Cookie("token-user"))
//c.Template = "blog.html"
c.Status = data["status"]
//c.Format = "markdown"
model.SaveContent(c)
Json(context, true).Set("content", c).End()
//c.Type = "article"
return
}
context.Layout("admin")
context.Render("admin/edit_page", map[string]interface{}{
"Title": "编辑文章",
"Page": c,
})
}
开发者ID:WytheOnly,项目名称:GoBlog,代码行数:38,代码来源:admin.go
示例11: AdminPage
func AdminPage(context *GoInk.Context) {
pages, pager := model.GetPageList(context.Int("page"), 10)
context.Layout("admin")
context.Render("admin/pages", map[string]interface{}{
"Title": "页面",
"Pages": pages,
"Pager": pager,
})
}
开发者ID:WytheOnly,项目名称:GoBlog,代码行数:9,代码来源:admin.go
示例12: AdminArticle
func AdminArticle(context *GoInk.Context) {
articles, pager := model.GetArticleList(context.Int("page"), 10)
context.Layout("admin")
context.Render("admin/articles", map[string]interface{}{
"Title": "文章",
"Articles": articles,
"Pager": pager,
})
}
开发者ID:WytheOnly,项目名称:GoBlog,代码行数:9,代码来源:admin.go
示例13: 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()
co := new(model.Comment)
co.Author = data["user"]
co.Email = data["email"]
co.Url = data["url"]
co.Content = strings.Replace(utils.Html2str(data["content"]), "\n", "<br/>", -1)
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()
}
开发者ID:WytheOnly,项目名称:GoBlog,代码行数:24,代码来源:home.go
示例14: CustomSetting
func CustomSetting(context *GoInk.Context) {
if context.Method == "POST" {
keys := context.Strings("key")
values := context.Strings("value")
for i, k := range keys {
model.SetSetting("c_"+k, values[i])
}
model.SyncSettings()
Json(context, true).End()
return
}
context.Layout("admin")
context.Render("admin/custom_setting", map[string]interface{}{
"Title": "自定义配置",
"Settings": model.GetCustomSettings(),
})
}
开发者ID:WytheOnly,项目名称:GoBlog,代码行数:17,代码来源:admin.go
示例15: Home
func Home(context *GoInk.Context) {
context.Layout("home")
page, _ := strconv.Atoi(context.Param("page"))
size, _ := strconv.Atoi(model.GetSetting("article_size"))
articles, pager := model.GetArticleList(page, size)
context.Render("home/home", map[string]interface{}{
"Articles": articles,
"Pager": pager,
})
}
开发者ID:WytheOnly,项目名称:GoBlog,代码行数:10,代码来源:home.go
示例16: AdminSetting
func AdminSetting(context *GoInk.Context) {
if context.Method == "POST" {
data := context.Input()
for k, v := range data {
model.SetSetting(k, v)
}
model.SyncSettings()
Json(context, true).End()
return
}
context.Layout("admin")
context.Render("admin/setting", map[string]interface{}{
"Title": "配置",
})
}
开发者ID:WytheOnly,项目名称:GoBlog,代码行数:15,代码来源:admin.go
示例17: Logout
func Logout(context *GoInk.Context) {
context.Cookie("token-user", "", "-3600")
context.Cookie("token-value", "", "-3600")
context.Redirect("/login/")
}
开发者ID:WytheOnly,项目名称:GoBlog,代码行数:5,代码来源:home.go
示例18: AdminComments
func AdminComments(context *GoInk.Context) {
if context.Method == "DELETE" {
id := context.Int("id")
cmt := model.GetCommentById(id)
model.RemoveComment(cmt.Cid, id)
Json(context, true).End()
return
}
if context.Method == "PUT" {
id := context.Int("id")
cmt2 := model.GetCommentById(id)
cmt2.Status = "approved"
cmt2.GetReader().Active = true
model.SaveComment(cmt2)
Json(context, true).End()
return
}
if context.Method == "POST" {
// get required data
pid := context.Int("pid")
cid := model.GetCommentById(pid).Cid
uid, _ := strconv.Atoi(context.Cookie("token-user"))
user := model.GetUserById(uid)
co := new(model.Comment)
co.Author = user.Nick
co.Email = user.Email
co.Url = user.Url
co.Content = strings.Replace(utils.Html2str(context.String("content")), "\n", "<br/>", -1)
co.Avatar = utils.Gravatar(co.Email, "50")
co.Pid = pid
co.Ip = context.Ip
co.UserAgent = context.UserAgent
co.IsAdmin = true
model.CreateComment(cid, co)
Json(context, true).Set("comment", co.ToJson()).End()
return
}
page := context.IntOr("page", 1)
comments, pager := model.GetCommentList(page, 6)
context.Layout("admin")
context.Render("admin/comments", map[string]interface{}{
"Title": "评论",
"Comments": comments,
"Pager": pager,
})
}
开发者ID:WytheOnly,项目名称:GoBlog,代码行数:47,代码来源:admin.go
示例19: Comments
func Comments(context *GoInk.Context, c *model.Content) string {
return context.Tpl("home/comment", map[string]interface{}{
"Content": c,
"Comments": c.Comments,
})
}
开发者ID:WytheOnly,项目名称:GoBlog,代码行数:6,代码来源:home.go
示例20: Login
func Login(context *GoInk.Context) {
if context.Method == "POST" {
data := context.Input()
user := model.GetUserByName(data["user"])
if user == nil {
Json(context, false).End()
return
}
if !user.CheckPassword(data["password"]) {
Json(context, false).End()
return
}
exp := 3600 * 24 * 3
expStr := strconv.Itoa(exp)
s := model.CreateToken(user, context, int64(exp))
context.Cookie("token-user", strconv.Itoa(s.UserId), expStr)
context.Cookie("token-value", s.Value, expStr)
Json(context, true).End()
return
}
if context.Cookie("token-value") != "" {
context.Redirect("/admin/")
return
}
context.Render("home/login", nil)
}
开发者ID:WytheOnly,项目名称:GoBlog,代码行数:26,代码来源:home.go
注:本文中的github.com/fuxiaohei/GoBlog/GoInk.Context类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论