本文整理汇总了Golang中github.com/issue9/logs.Error函数的典型用法代码示例。如果您正苦于以下问题:Golang Error函数的具体用法?Golang Error怎么用?Golang Error使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Error函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: pagePosts
// 首页或是列表页
func pagePosts(w http.ResponseWriter, r *http.Request) {
info, err := getInfo()
if err != nil {
logs.Error("pagePosts:", err)
pageHttpStatusCode(w, r, http.StatusInternalServerError)
return
}
page := conv.MustInt(r.FormValue("page"), 1)
if page == 1 {
info.Canonical = app.URL(app.HomeURL())
} else if page > 1 { // 为1的时候,不需要prev
info.Canonical = app.URL(app.PostsURL(page))
info.PrevPage = &Anchor{Title: "上一页", Link: app.PostsURL(page - 1)}
}
if page*opt.SidebarSize < info.PostSize {
info.NextPage = &Anchor{Title: "下一页", Link: app.PostsURL(page + 1)}
}
posts, err := getPosts(page - 1)
if err != nil {
logs.Error("pagePosts:", err)
pageHttpStatusCode(w, r, http.StatusInternalServerError)
return
}
data := map[string]interface{}{
"info": info,
"posts": posts,
}
render(w, r, "posts", data, map[string]string{"Content-Type": "text/html"})
}
开发者ID:caixw,项目名称:typing,代码行数:34,代码来源:front.go
示例2: adminSetPostState
func adminSetPostState(w http.ResponseWriter, r *http.Request, state int) {
id, ok := util.ParamID(w, r, "id")
if !ok {
return
}
p := &models.Post{ID: id}
if err := db.Select(p); err != nil {
logs.Error("adminSetPostState:", err)
util.RenderJSON(w, http.StatusInternalServerError, nil, nil)
return
}
// 不可能存在状态值为0的文章,出现此值,表明数据库没有该条记录
if p.State == models.PostStateAll {
util.RenderJSON(w, http.StatusNotFound, nil, nil)
return
}
p = &models.Post{ID: id, State: state}
if _, err := db.Update(p); err != nil {
logs.Error("adminSetPostState:", err)
util.RenderJSON(w, http.StatusInternalServerError, nil, nil)
return
}
if err := stats.UpdatePostsSize(); err != nil {
logs.Error("admin.adminSetPostState:", err)
}
lastUpdated()
util.RenderJSON(w, http.StatusCreated, "{}", nil)
}
开发者ID:caixw,项目名称:typing,代码行数:32,代码来源:posts.go
示例3: pageTags
// /tags
func pageTags(w http.ResponseWriter, r *http.Request) {
info, err := getInfo()
if err != nil {
logs.Error("pageTags:", err)
pageHttpStatusCode(w, r, http.StatusInternalServerError)
return
}
info.Canonical = app.URL(app.TagsURL())
info.Title = "标签"
sql := `SELECT {id} AS {ID}, {name} AS {Name}, {title} AS {Title} FROM #tags`
rows, err := db.Query(true, sql)
if err != nil {
logs.Error("pageTags:", err)
pageHttpStatusCode(w, r, http.StatusInternalServerError)
return
}
defer rows.Close()
tags := make([]*Tag, 0, 100)
if _, err = fetch.Obj(&tags, rows); err != nil {
logs.Error("pageTags:", err)
pageHttpStatusCode(w, r, http.StatusInternalServerError)
return
}
data := map[string]interface{}{"info": info, "tags": tags}
render(w, r, "tags", data, map[string]string{"Content-Type": "text/html"})
}
开发者ID:caixw,项目名称:typing,代码行数:30,代码来源:front.go
示例4: adminGetPosts
// @api get /admin/api/posts 获取文章列表
// @apiQuery page int 页码,从0开始
// @apiQuery size int 显示尺寸
// @apiQuery state int 状态
// @apiGroup admin
//
// @apiSuccess ok 200
// @apiParam count int 符合条件的所有记录数量,不包含page和size条件
// @apiParam posts array 当前页的记录数量
func adminGetPosts(w http.ResponseWriter, r *http.Request) {
var page, size, state int
var ok bool
if state, ok = util.QueryInt(w, r, "state", models.CommentStateAll); !ok {
return
}
sql := db.SQL().Table("#posts")
if state != models.PostStateAll {
sql.And("{state}=?", state)
}
count, err := sql.Count(true)
if err != nil {
logs.Error("adminGetPosts:", err)
util.RenderJSON(w, http.StatusInternalServerError, nil, nil)
return
}
if page, ok = util.QueryInt(w, r, "page", 0); !ok {
return
}
if size, ok = util.QueryInt(w, r, "size", opt.PageSize); !ok {
return
}
sql.Limit(size, page*size)
maps, err := sql.SelectMapString(true, "*")
if err != nil {
logs.Error("adminGetPosts:", err)
util.RenderJSON(w, http.StatusInternalServerError, nil, nil)
return
}
util.RenderJSON(w, http.StatusOK, map[string]interface{}{"count": count, "posts": maps}, nil)
}
开发者ID:caixw,项目名称:typing,代码行数:43,代码来源:posts.go
示例5: adminPutCurrentTheme
// @api put /admin/api/themes/current 更改当前的主题
// @apiGroup admin
//
// @apiRequest json
// @apiHeader Authorization xxx
// @apiParam value string 新值
//
// @apiSuccess 200 OK
func adminPutCurrentTheme(w http.ResponseWriter, r *http.Request) {
v := &struct {
Value string `json:"value"`
}{}
if !util.ReadJSON(w, r, v) {
return
}
if len(v.Value) == 0 {
util.RenderJSON(w, http.StatusBadRequest, &util.ErrorResult{Message: "必须指定一个值!"}, nil)
return
}
if err := app.SetOption("theme", v.Value, false); err != nil {
logs.Error("adminPutTheme:", err)
util.RenderJSON(w, http.StatusInternalServerError, nil, nil)
return
}
if err := front.Switch(v.Value); err != nil {
logs.Error("adminPutTheme:", err)
util.RenderJSON(w, http.StatusInternalServerError, nil, nil)
return
}
lastUpdated()
util.RenderJSON(w, http.StatusNoContent, nil, nil)
}
开发者ID:caixw,项目名称:typing,代码行数:35,代码来源:theme.go
示例6: pageTag
// /tags/1.html
func pageTag(w http.ResponseWriter, r *http.Request) {
tagName, ok := util.ParamString(w, r, "id")
if !ok {
return
}
tagName = strings.TrimSuffix(tagName, opt.Suffix)
sql := `SELECT {id} AS {ID}, {name} AS {Name}, {title} AS {Title}, {description} AS {Description}
FROM #tags
WHERE {name}=?`
rows, err := db.Query(true, sql, tagName)
if err != nil {
logs.Error("pageTag:", err)
pageHttpStatusCode(w, r, http.StatusInternalServerError)
return
}
defer rows.Close()
tag := &Tag{}
if _, err = fetch.Obj(tag, rows); err != nil {
logs.Error("pageTag:", err)
pageHttpStatusCode(w, r, http.StatusInternalServerError)
return
}
info, err := getInfo()
if err != nil {
logs.Error("pageTag:", err)
pageHttpStatusCode(w, r, http.StatusInternalServerError)
return
}
info.Canonical = app.URL(tag.Permalink())
info.Title = tag.Title
page := conv.MustInt(r.FormValue("page"), 1)
if page < 1 { // 不能小于1
page = 1
} else if page > 1 { // 为1的时候,不需要prev
info.PrevPage = &Anchor{Title: "上一页", Link: app.TagURL(tagName, page-1)}
}
if page*opt.SidebarSize < tag.Count() {
info.NextPage = &Anchor{Title: "下一页", Link: app.TagURL(tagName, page+1)}
}
posts, err := getTagPosts(page-1, tag.ID)
if err != nil {
logs.Error("pageTag:", err)
pageHttpStatusCode(w, r, http.StatusInternalServerError)
return
}
data := map[string]interface{}{
"info": info,
"tag": tag,
"posts": posts,
}
render(w, r, "tag", data, map[string]string{"Content-Type": "text/html"})
}
开发者ID:caixw,项目名称:typing,代码行数:59,代码来源:front.go
示例7: adminPutTag
// @api put /admin/api/tags/{id} 修改某id的标签内容
// @apiParam id int 需要修改的标签id
// @apiGroup admin
//
// @apiRequest json
// @apiHeader Authorization xxx
// @apiParam name string 唯一名称
// @apiParam title string 显示的标题
// @apiParam description string 描述信息,可以是html
// @apiExample json
// {
// "name": "tag-1",
// "title":"标签1",
// "description": "<h1>desc</h1>"
// }
//
// @apiSuccess 204 no content
//
// @apiError 400 bad request
// @apiParam message string 错误信息
// @apiParam detail array 说细的错误信息,用于描述哪个字段有错
// @apiExample json
// {
// "message": "格式错误",
// "detail":[
// {"title":"不能包含特殊字符"},
// {"name": "已经存在同名"}
// ]
// }
func adminPutTag(w http.ResponseWriter, r *http.Request) {
t := &models.Tag{}
if !util.ReadJSON(w, r, t) {
return
}
// 检测是否为空
errs := &util.ErrorResult{Message: "格式错误", Detail: map[string]string{}}
if len(t.Name) == 0 {
errs.Add("name", "不能为空")
}
if len(t.Title) == 0 {
errs.Add("title", "不能为空")
}
if errs.HasErrors() {
util.RenderJSON(w, http.StatusBadRequest, errs, nil)
return
}
var ok bool
t.ID, ok = util.ParamID(w, r, "id")
if !ok {
return
}
// 检测是否存在同名
titleExists, nameExists, err := tagIsExists(t)
if err != nil {
logs.Error("adminPutTag:", err)
util.RenderJSON(w, http.StatusInternalServerError, nil, nil)
return
}
if titleExists {
errs.Add("title", "与已有标签同名")
}
if nameExists {
errs.Add("name", "与已有标签同名")
}
if errs.HasErrors() {
util.RenderJSON(w, http.StatusBadRequest, errs, nil)
return
}
if _, err := db.Update(t); err != nil {
logs.Error("adminPutTag:", err)
util.RenderJSON(w, http.StatusInternalServerError, nil, nil)
return
}
lastUpdated()
util.RenderJSON(w, http.StatusNoContent, nil, nil)
}
开发者ID:caixw,项目名称:typing,代码行数:81,代码来源:tags.go
示例8: adminGetPost
// @api get /admin/api/posts/{id} 获取某一篇文章的详细内容
// @apiGroup admin
//
// @apiRequest json
// @apiHeader Authorization xxx
//
// @apiSuccess 200 OK
// @apiParam id int id值
// @apiParam name string 唯一名称,可以为空
// @apiParam title string 标题
// @apiParam summary string 文章摘要
// @apiParam content string 文章内容
// @apiParam state int 状态
// @apiParam order int 排序
// @apiParam created int 创建时间
// @apiParam modified int 修改时间
// @apiParam template string 所使用的模板
// @apiParam allowPing bool 允许ping
// @apiParam allowComment bool 允许评论
// @apiParam tags array 关联的标签。
func adminGetPost(w http.ResponseWriter, r *http.Request) {
id, ok := util.ParamID(w, r, "id")
if !ok {
return
}
p := &models.Post{ID: id}
if err := db.Select(p); err != nil {
logs.Error("adminGetPost:", err)
util.RenderJSON(w, http.StatusInternalServerError, nil, nil)
return
}
tags, err := getPostTags(id)
if err != nil {
logs.Error("adminGetPost:", err)
util.RenderJSON(w, http.StatusInternalServerError, nil, nil)
return
}
obj := &struct {
ID int64 `json:"id"`
Name string `json:"name"`
Title string `json:"title"`
Summary string `json:"summary"`
Content string `json:"content"`
State int `json:"state"`
Order int `json:"order"`
Created int64 `json:"created"`
Modified int64 `json:"modified"`
Template string `json:"template"`
AllowPing bool `json:"allowPing"`
AllowComment bool `json:"allowComment"`
Tags []*models.Tag `json:"tags"`
}{
ID: p.ID,
Name: p.Name,
Title: p.Title,
Summary: p.Summary,
Content: p.Content,
State: p.State,
Order: p.Order,
Created: p.Created,
Modified: p.Modified,
Template: p.Template,
AllowPing: p.AllowPing,
AllowComment: p.AllowComment,
Tags: tags,
}
util.RenderJSON(w, http.StatusOK, obj, nil)
}
开发者ID:caixw,项目名称:typing,代码行数:71,代码来源:posts.go
示例9: adminPostTag
// @api post /admin/api/tags 添加新标签
// @apiGroup admin
//
// @apiRequest json
// @apiHeader Authorization xxx
// @apiParam name string 唯一名称
// @apiParam title string 显示的标题
// @apiParam description string 描述信息,可以是html
// @apiExample json
// {
// "name": "tag-1",
// "title":"标签1",
// "description": "<h1>desc</h1>"
// }
//
// @apiSuccess 201 created
// @apiError 400 bad request
// @apiParam message string 错误信息
// @apiParam detail array 说细的错误信息,用于描述哪个字段有错
// @apiExample json
// {
// "message": "格式错误",
// "detail":[
// {"title":"不能包含特殊字符"},
// {"name": "已经存在同名"}
// ]
// }
func adminPostTag(w http.ResponseWriter, r *http.Request) {
t := &models.Tag{}
if !util.ReadJSON(w, r, t) {
return
}
errs := &util.ErrorResult{Message: "格式错误"}
if t.ID != 0 {
errs.Add("id", "不允许的字段")
}
if len(t.Title) == 0 {
errs.Add("title", "不能为空")
}
if len(t.Name) == 0 {
errs.Add("name", "不能为空")
}
if errs.HasErrors() {
util.RenderJSON(w, http.StatusBadRequest, errs, nil)
return
}
t.ID = 0
titleExists, nameExists, err := tagIsExists(t)
if err != nil {
logs.Error("adminPostTag:", err)
util.RenderJSON(w, http.StatusInternalServerError, nil, nil)
return
}
if titleExists {
errs.Add("title", "已有同名字体段")
}
if nameExists {
errs.Add("name", "已有同名字体段")
}
if errs.HasErrors() {
util.RenderJSON(w, http.StatusBadRequest, errs, nil)
return
}
if _, err := db.Insert(t); err != nil {
logs.Error("adminPostTag:", err)
util.RenderJSON(w, http.StatusInternalServerError, nil, nil)
return
}
lastUpdated()
util.RenderJSON(w, http.StatusCreated, "{}", nil)
}
开发者ID:caixw,项目名称:typing,代码行数:75,代码来源:tags.go
示例10: adminPatchOption
// @api patch /admin/api/options/{key} 修改设置项的值
// @apiParam key string 需要修改项的key
// @apiGroup admin
//
// @apiRequest json
// @apiHeader Authorization xxx
// @apiParam value string 新值
// @apiExample json
// { "value": "abcdef" }
// @apiSuccess 204 no content
func adminPatchOption(w http.ResponseWriter, r *http.Request) {
key, ok := util.ParamString(w, r, "key")
if !ok {
return
}
if _, found := app.GetOption(key); !found {
util.RenderJSON(w, http.StatusNotFound, nil, nil)
return
}
data := &struct {
Value string `json:"value"`
}{}
if !util.ReadJSON(w, r, data) {
return
}
if err := app.SetOption(key, data.Value, false); err != nil {
logs.Error("adminPatchOption:", err)
util.RenderJSON(w, http.StatusInternalServerError, nil, nil)
return
}
lastUpdated()
util.RenderJSON(w, http.StatusNoContent, nil, nil)
}
开发者ID:caixw,项目名称:typing,代码行数:37,代码来源:options.go
示例11: adminChangePassword
// @api put /admin/api/password 理发密码
// @apiGroup admin
// @apiRequest json
// @apiHeader Authorization xxx
// @apiParam old string 旧密码
// @apiParam new string 新密码
// @apiExample json
// {
// "old": "123",
// "new": "456"
// }
//
// @apiSuccess 204 no content
func adminChangePassword(w http.ResponseWriter, r *http.Request) {
l := &struct {
Old string `json:"old"`
New string `json:"new"`
}{}
if !util.ReadJSON(w, r, l) {
return
}
errs := &util.ErrorResult{Message: "提交数据错误", Detail: map[string]string{}}
if len(l.New) == 0 {
errs.Add("new", "新密码不能为空")
}
if opt.Password != app.Password(l.Old) {
errs.Add("old", "旧密码错误")
}
if len(errs.Detail) > 0 {
util.RenderJSON(w, http.StatusBadRequest, errs, nil)
return
}
o := &models.Option{Key: "password", Value: app.Password(l.New)}
if _, err := db.Update(o); err != nil {
logs.Error("adminChangePassword:", err)
util.RenderJSON(w, http.StatusInternalServerError, nil, nil)
return
}
opt.Password = o.Value
util.RenderJSON(w, http.StatusNoContent, nil, nil)
}
开发者ID:caixw,项目名称:typing,代码行数:44,代码来源:users.go
示例12: initRoute
// 初始化路由项
func initRoute() error {
m, err := web.NewModule("feed")
if err != nil {
return err
}
m.GetFunc("/sitemap.xml", func(w http.ResponseWriter, r *http.Request) {
sitemapMutex.Lock()
defer sitemapMutex.Unlock()
if _, err := w.Write(sitemap.Bytes()); err != nil {
logs.Error("feed.initRoute.route-/sitemap.xml:", err)
w.WriteHeader(http.StatusNotFound) // 若是出错,给客户端的信息提示为404
}
})
// NOTE:若修改此路由,请同时修改sitemap.xml中的相对应的.xsl路径
m.GetFunc("/sitemap.xsl", func(w http.ResponseWriter, r *http.Request) {
if _, err := w.Write(static.Sitemap); err != nil {
logs.Error("feed.initRoute.route-/sitemap.xsl:", err)
w.WriteHeader(http.StatusNotFound)
}
})
m.GetFunc("/rss.xml", func(w http.ResponseWriter, r *http.Request) {
rssMutex.Lock()
defer rssMutex.Unlock()
if _, err := w.Write(rss.Bytes()); err != nil {
logs.Error("feed.initRoute.route-/rss.xml:", err)
w.WriteHeader(http.StatusNotFound)
}
})
m.GetFunc("/atom.xml", func(w http.ResponseWriter, r *http.Request) {
atomMutex.Lock()
defer atomMutex.Unlock()
if _, err := w.Write(atom.Bytes()); err != nil {
logs.Error("feed.initRoute.route-/atom.xml:", err)
w.WriteHeader(http.StatusNotFound)
}
})
return nil
}
开发者ID:caixw,项目名称:typing,代码行数:47,代码来源:feed.go
示例13: render
// 输出指定模板
func render(w http.ResponseWriter, r *http.Request, name string, data interface{}, headers map[string]string) {
if cfg.Debug { // 调试状态下,实时加载模板
if err := Switch(currentTheme); err != nil {
logs.Error("front.render:", err)
}
}
for key, val := range headers {
w.Header().Set(key, val)
}
err := tpl.ExecuteTemplate(w, name, data)
if err != nil {
logs.Error("front.Render:", err)
pageHttpStatusCode(w, r, http.StatusInternalServerError)
return
}
}
开发者ID:caixw,项目名称:typing,代码行数:19,代码来源:themes.go
示例14: adminPutSitemap
// @api put /admin/api/feed/sitemap 重新生成sitemap
// @apiGroup admin
//
// @apiRequest json
// @apiHeader Authorization xxx
//
// @apiSuccess 200 Ok
func adminPutSitemap(w http.ResponseWriter, r *http.Request) {
err := feed.BuildSitemap()
if err != nil {
logs.Error(err)
util.RenderJSON(w, http.StatusInternalServerError, nil, nil)
return
}
util.RenderJSON(w, http.StatusOK, "{}", nil)
}
开发者ID:caixw,项目名称:typing,代码行数:17,代码来源:options.go
示例15: Tags
// 获取与当前文章相关的标签。
func (p *Post) Tags() []*Tag {
sql := `SELECT t.{name} AS {Name}, t.{title} AS {Title} FROM #relationships AS r
LEFT JOIN #tags AS t on t.{id}=r.{tagID}
WHERE r.{postID}=?`
rows, err := db.Query(true, sql, p.ID)
if err != nil {
logs.Error("front.Post.Tags:", err)
return nil
}
defer rows.Close()
tags := make([]*Tag, 0, 5)
if _, err = fetch.Obj(&tags, rows); err != nil {
logs.Error("front.Post.Tags:", err)
return nil
}
return tags
}
开发者ID:caixw,项目名称:typing,代码行数:20,代码来源:post.go
示例16: adminDeleteComment
// @api delete /admin/api/comments/{id} 删除某条评论
// @apiParam id int 评论的id值
// @apiGroup admin
//
// @apiSuccess 204 no content
func adminDeleteComment(w http.ResponseWriter, r *http.Request) {
id, ok := util.ParamID(w, r, "id")
if !ok {
return
}
c := &models.Comment{ID: id}
if _, err := db.Delete(c); err != nil {
logs.Error("adminDeleteComment:", err)
util.RenderJSON(w, http.StatusInternalServerError, nil, nil)
return
}
if err := stats.UpdateCommentsSize(); err != nil {
logs.Error("admin.adminDeleteComment:", err)
}
lastUpdated()
util.RenderJSON(w, http.StatusNoContent, nil, nil)
}
开发者ID:caixw,项目名称:typing,代码行数:25,代码来源:comments.go
示例17: adminPutComment
// @api put /admin/api/comments/{id} 修改评论,只能修改管理员发布的评论
// @apiParam id int 需要修改的评论id
// @apiGroup admin
//
// @apiRequest json
// @apiParam content string 新的评论内容
// @apiExample json
// { "content", "content..." }
//
// @apiSuccess 200 ok
func adminPutComment(w http.ResponseWriter, r *http.Request) {
id, ok := util.ParamID(w, r, "id")
if !ok {
return
}
c := &models.Comment{ID: id}
cnt, err := db.Count(c)
if err != nil {
logs.Error("putComment:", err)
util.RenderJSON(w, http.StatusInternalServerError, nil, nil)
return
}
if cnt == 0 {
util.RenderJSON(w, http.StatusNotFound, nil, nil)
return
}
ct := &struct {
Content string `json:"content"`
}{}
if !util.ReadJSON(w, r, ct) {
return
}
c.Content = ct.Content
if _, err = db.Update(c); err != nil {
logs.Error("putComment", err)
util.RenderJSON(w, http.StatusInternalServerError, nil, nil)
return
}
if err := stats.UpdateCommentsSize(); err != nil {
logs.Error("admin.adminPutComment:", err)
}
lastUpdated()
util.RenderJSON(w, http.StatusNoContent, nil, nil)
}
开发者ID:caixw,项目名称:typing,代码行数:51,代码来源:comments.go
示例18: adminPostLogin
// @api post /admin/api/login 登录
// @apiGroup admin
//
// @apiRequest json
// @apiParam password string 登录密码
// @apiExample json
// { "password": "12345" }
//
// @apiSuccess 201
// @apiHeader Cache-Control:no-cache
// @apiHeader Pragma:no-cache
// @apiParam token string 登录凭证;
// @apiExample json
// { "token": "adfwerqeqaeqe313aa" }
func adminPostLogin(w http.ResponseWriter, r *http.Request) {
inst := &struct {
Password string `json:"password"`
}{}
if !util.ReadJSON(w, r, inst) {
return
}
if app.Password(inst.Password) != opt.Password {
util.RenderJSON(w, http.StatusUnauthorized, nil, nil)
return
}
ret := make([]byte, 64)
n, err := io.ReadFull(rand.Reader, ret)
if err != nil {
logs.Error("login:无法产生一个随机的token", err)
util.RenderJSON(w, http.StatusInternalServerError, nil, nil)
return
}
if n == 0 {
logs.Error("login:无法产生一个随机的token")
util.RenderJSON(w, http.StatusInternalServerError, nil, nil)
return
}
token = utils.MD5(string(ret))
if len(token) == 0 {
logs.Error("login:无法正确生成登录的token")
util.RenderJSON(w, http.StatusInternalServerError, nil, nil)
return
}
// 记录日志出错,仅输出错误内容,但不返回500错误。
if err = writeLastLogs(r); err != nil {
logs.Error("login:", err)
}
util.RenderJSON(w, http.StatusCreated, map[string]string{"token": token}, nil)
}
开发者ID:caixw,项目名称:typing,代码行数:54,代码来源:users.go
示例19: adminGetTags
// @api get /admin/api/tags 获取所有标签信息
// @apiGroup admin
//
// @apiRequest json
// @apiheader Authorization xxx
//
// @apiSuccess 200 OK
// @apiParam tags array 所有标签的列表
func adminGetTags(w http.ResponseWriter, r *http.Request) {
sql := `SELECT m.{name}, m.{title}, m.{description}, m.{id},count(r.{tagID}) AS {count}
FROM #tags AS m
LEFT JOIN #relationships AS r ON m.{id}=r.{tagID}
GROUP BY m.{id}`
rows, err := db.Query(true, sql)
if err != nil {
logs.Error("getTags:", err)
util.RenderJSON(w, http.StatusInternalServerError, nil, nil)
return
}
maps, err := fetch.MapString(false, rows)
rows.Close()
if err != nil {
logs.Error("getTags:", err)
util.RenderJSON(w, http.StatusInternalServerError, nil, nil)
return
}
util.RenderJSON(w, http.StatusOK, map[string]interface{}{"tags": maps}, nil)
}
开发者ID:caixw,项目名称:typing,代码行数:30,代码来源:tags.go
示例20: CommentsSize
// 评论数量
func (p *Post) CommentsSize() int {
if size, found := stats.Posts[p.ID]; found {
return size
}
c := &models.Comment{PostID: p.ID, State: models.CommentStateApproved}
size, err := db.Count(c)
if err != nil {
logs.Error("front.Post.CommentsSize:", err)
return 0
}
stats.Posts[p.ID] = size
return size
}
开发者ID:caixw,项目名称:typing,代码行数:15,代码来源:post.go
注:本文中的github.com/issue9/logs.Error函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论