本文整理匯總了Golang中github.com/fuxiaohei/purine/src/log.Error函數的典型用法代碼示例。如果您正苦於以下問題:Golang Error函數的具體用法?Golang Error怎麽用?Golang Error使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Error函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: NewSiteInitData
// new site init data
func NewSiteInitData(engine *xorm.Engine) {
// default user
user := &model.User{
Name: "admin",
Nick: "admin",
Email: "[email protected]",
Url: "#",
AvatarUrl: utils.GravatarLink("[email protected]"),
Profile: "this is an administrator",
Role: model.USER_ROLE_ADMIN,
Status: model.USER_STATUS_ACTIVE,
}
user.Salt = utils.Md5String("123456789")[8:24]
user.Password = utils.Sha256String("123456789" + user.Salt)
if _, err := engine.Insert(user); err != nil {
log.Error("NewSite | %s", err.Error())
return
}
// default article
article := &model.Article{
Title: "Welcome to Purine",
Link: "welcome-to-purine",
Preview: blogPreview,
Body: blogContent,
TagString: "blog",
Hits: 1,
Comments: 0,
Status: model.ARTICLE_STATUS_PUBLISH,
CommentStatus: model.ARTICLE_COMMENT_OPEN,
AuthorId: user.Id,
}
if _, err := engine.Insert(article); err != nil {
log.Error("NewSite | %s", err.Error())
return
}
// default settings
settings := make([]interface{}, 0)
settings = append(settings, &model.Setting{"title", "Purine", 0})
settings = append(settings, &model.Setting{"subtitle", "a simple blog engine", 0})
settings = append(settings, &model.Setting{"desc", "a simple blog engine by golang", 0})
settings = append(settings, &model.Setting{"keyword", "purine,blog,golang", 0})
settings = append(settings, &model.Setting{"theme", "default", 0})
settings = append(settings, &model.Setting{"baseurl", "http://localhost:9999/", 0})
settings = append(settings, &model.Setting{"media_imageext", ".jpg,.jpeg,.png,.gif", 0})
settings = append(settings, &model.Setting{"media_fileext", ".txt,.zip,.doc,.xls,.ppt,.pdf", 0})
settings = append(settings, &model.Setting{"media_nameformat", ":hash", 0})
settings = append(settings, &model.Setting{"media_maxsize", strconv.Itoa(2 * 1024 * 1024), 0})
if _, err := engine.Insert(settings...); err != nil {
log.Error("NewSite | %s", err.Error())
return
}
}
示例2: SaveComment
// save a comment,
// always insert new
func SaveComment(c *Comment) error {
if _, err := vars.Db.Insert(c); err != nil {
log.Error("Db|SaveComment|%s", err.Error())
return err
}
return nil
}
示例3: SaveSetting
// save setting with key, value and owner id
func SaveSetting(key, value string, uid int64) error {
if _, err := vars.Db.Where("name = ?", key).Delete(new(Setting)); err != nil {
log.Error("Db|SaveSetting|%s,%s,%d|%s", key, value, uid, err.Error())
return err
}
s := &Setting{
Name: key,
Value: value,
UserId: uid,
}
if _, err := vars.Db.Insert(s); err != nil {
log.Error("Db|SaveSetting|%s,%s,%d|%s", key, value, uid, err.Error())
return err
}
return nil
}
示例4: GetCurrentTheme
// get current theme
func GetCurrentTheme() (*Theme, error) {
themeSetting, err := GetSettings("theme")
if err != nil {
return nil, err
}
t := new(Theme)
t.Directory = themeSetting["theme"]
t.IsCurrent = true
tomlFile := path.Join("static", t.Directory, "theme.toml")
if com.IsFile(tomlFile) {
if _, err := toml.DecodeFile(tomlFile, t); err != nil {
log.Error("Db|GetCurrentTheme|%s|%s", tomlFile, err.Error())
return nil, err
}
}
// fill data
if t.Name == "" {
t.Name = t.Directory
}
if t.Version == "" {
t.Version = "0.0"
}
return t, nil
}
示例5: saveTags
func saveTags(id int64, tagStr string) error {
// delete old tags
if _, err := vars.Db.Where("article_id = ?", id).Delete(new(Tag)); err != nil {
log.Error("Db|SaveTags|%d,%s|%s", id, tagStr, err.Error())
return err
}
// save new tags
tags := strings.Split(strings.Replace(tagStr, ",", ",", -1), ",")
for _, t := range tags {
if _, err := vars.Db.Insert(&Tag{ArticleId: id, Tag: t}); err != nil {
log.Error("Db|SaveTags|%d,%s|%s", id, t, err.Error())
return err
}
}
return nil
}
示例6: CountApprovedCommentsByEmail
// check email's approved comment count
func CountApprovedCommentsByEmail(email string) int64 {
c, err := vars.Db.Where("status = ? AND email = ?", COMMENT_STATUS_APPROVED, email).Count(new(Comment))
if err != nil {
log.Error("Db|CountApprovedCommentsByEmail|%s|%s", email, err.Error())
return 0
}
return c
}
示例7: SavePage
// save page.
// if page.Id, update page,
// or insert new page;
// return the saved page.
func SavePage(p *Page) (*Page, error) {
if p.Id > 0 {
if _, err := vars.Db.Where("id = ?", p.Id).
Cols("title,link,update_time,body,topic,status,comment_status").
Update(p); err != nil {
log.Error("Db|SavePage|%d|%s", p.Id, err.Error())
return nil, err
}
} else {
if _, err := vars.Db.Insert(p); err != nil {
log.Error("Db|SavePage|%d|%s", p.Id, err.Error())
return nil, err
}
}
return GetPageBy("id", p.Id)
}
示例8: UpdateUser
// update user profile columns
func UpdateUser(u *User) error {
if _, err := vars.Db.Cols("name,nick,email,url,profile,avatar_url").
Where("id = ?", u.Id).Update(u); err != nil {
log.Error("Db|UpdateUser|%d|%s", u.Id, err.Error())
return err
}
return nil
}
示例9: ChangeCommentStatus
// change comment status
func ChangeCommentStatus(cid int64, status string) (*Comment, error) {
c := &Comment{Status: status}
if _, err := vars.Db.Id(cid).Cols("status").Update(c); err != nil {
log.Error("Db|ChangeCommentStatus|%d,%s|%s", cid, status, err.Error())
return nil, err
}
return GetCommentBy("id", cid)
}
示例10: GetArticleBy
// get article by column and value
func GetArticleBy(col string, v interface{}) (*Article, error) {
a := new(Article)
if isIdColumn(col) {
if _, err := vars.Db.Id(v).Get(a); err != nil {
log.Error("Db|GetArticleBy|%s,%v|%s", col, v, err.Error())
return nil, err
}
} else {
if _, err := vars.Db.Where(col+" = ?", v).Get(a); err != nil {
log.Error("Db|GetArticleBy|%s,%v|%s", col, v, err.Error())
return nil, err
}
}
if a.Id > 0 {
return a, nil
}
return nil, nil
}
示例11: ListGeneralArticle
// list general articles,
// contains publish and draft articles
func ListGeneralArticle(page, size int64, order string) ([]*Article, error) {
articles := make([]*Article, 0)
if err := vars.Db.Where("status != ?", ARTICLE_STATUS_DELETE).
Limit(int(size), int((page-1)*size)).OrderBy(order).Find(&articles); err != nil {
log.Error("Db|ListGeneralArticle|%d,%d|%s|%s", page, size, order, err.Error())
return nil, err
}
return articles, nil
}
示例12: RemoveArticle
// remove article by id
func RemoveArticle(id int64) error {
a := new(Article)
a.Status = ARTICLE_STATUS_DELETE
if _, err := vars.Db.Where("id = ?", id).Cols("status").Update(a); err != nil {
log.Error("Db|RemoveArticle|%d|%s", id, err.Error())
return err
}
return nil
}
示例13: ListStatusArticle
// list articles with one status
func ListStatusArticle(status string, page, size int64, order string) ([]*Article, error) {
articles := make([]*Article, 0)
if err := vars.Db.Where("status = ?", status).
Limit(int(size), int((page-1)*size)).OrderBy(order).Find(&articles); err != nil {
log.Error("Db|ListStatusArticle|%s|%d,%d|%s|%s", status, page, size, order, err.Error())
return nil, err
}
return articles, nil
}
示例14: GetPageBy
// get page by column and value
func GetPageBy(col string, v interface{}) (*Page, error) {
p := new(Page)
if isIdColumn(col) {
if _, err := vars.Db.Id(v).Get(p); err != nil {
log.Error("Db|GetPageBy|%s,%v|%s", col, v, err.Error())
return nil, err
}
} else {
if _, err := vars.Db.Where(col+" = ?", v).Get(p); err != nil {
log.Error("Db|GetPageBy|%s,%v|%s", col, v, err.Error())
return nil, err
}
}
if p.Id > 0 {
return p, nil
}
return nil, nil
}
示例15: GetCommentBy
// get a comment by column and value
func GetCommentBy(col string, v interface{}) (*Comment, error) {
c := new(Comment)
if isIdColumn(col) {
if _, err := vars.Db.Id(v).Get(c); err != nil {
log.Error("Db|GetCommentBy|%s,%v|%s", col, v, err.Error())
return nil, err
}
} else {
if _, err := vars.Db.Where(col+" = ?", v).Get(c); err != nil {
log.Error("Db|GetCommentBy|%s,%v|%s", col, v, err.Error())
return nil, err
}
}
if c.Id > 0 {
return c, nil
}
return nil, nil
}