本文整理匯總了Golang中github.com/lunny/log.Error函數的典型用法代碼示例。如果您正苦於以下問題:Golang Error函數的具體用法?Golang Error怎麽用?Golang Error使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Error函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: flushIndex
func (l *BinLog) flushIndex() error {
data := strings.Join(l.logNames, "\n")
bakName := fmt.Sprintf("%s.bak", l.indexName)
f, err := os.OpenFile(bakName, os.O_WRONLY|os.O_CREATE, 0666)
if err != nil {
log.Error("create binlog bak index error %s", err.Error())
return err
}
if _, err := f.WriteString(data); err != nil {
log.Error("write binlog index error %s", err.Error())
f.Close()
return err
}
f.Close()
if err := os.Rename(bakName, l.indexName); err != nil {
log.Error("rename binlog bak index error %s", err.Error())
return err
}
return nil
}
示例2: Post
func (this *NewPost) Post() error {
if this.CheckActiveRedirect() {
return nil
}
var err error
form := post.PostForm{Locale: this.Locale}
topicSlug := this.GetString("topic")
if len(topicSlug) > 0 {
topic, err := models.GetTopicBySlug(topicSlug)
if err == nil {
form.Category = topic.CategoryId
form.Topic = topic.Id
this.Data["Topic"] = topic
} else {
log.Error("Can not find topic by slug:", topicSlug)
}
} else {
topicId, err := this.GetInt("Topic")
if err == nil {
topic, err := models.GetTopicById(topicId)
if err == nil {
form.Category = topic.CategoryId
form.Topic = topic.Id
this.Data["Topic"] = topic
} else {
log.Error("Can not find topic by id:", topicId)
}
} else {
log.Error("Parse param Topic from request failed", err)
}
}
if categorySlug := this.GetString("category"); categorySlug != "" {
log.Debug("Find category slug:", categorySlug)
category, err := models.GetCategoryBySlug(categorySlug)
if err != nil {
log.Error("Get category error", err)
}
this.Data["Category"] = &category
}
err = models.FindTopics(&form.Topics)
if err != nil {
return err
}
if !this.ValidFormSets(&form) {
this.Redirect("/new")
return nil
}
var post models.Post
if err := form.SavePost(&post, &this.User); err == nil {
this.JsStorage("deleteKey", "post/new")
this.Redirect(post.Link())
return nil
}
return this.Render("post/new.html", this.Data)
}
示例3: loadIndex
func (l *BinLog) loadIndex() error {
l.indexName = path.Join(l.path, fmt.Sprintf("ledis-bin.index"))
if _, err := os.Stat(l.indexName); os.IsNotExist(err) {
//no index file, nothing to do
} else {
indexData, err := ioutil.ReadFile(l.indexName)
if err != nil {
return err
}
lines := strings.Split(string(indexData), "\n")
for _, line := range lines {
line = strings.Trim(line, "\r\n ")
if len(line) == 0 {
continue
}
if _, err := os.Stat(path.Join(l.path, line)); err != nil {
log.Error("load index line %s error %s", line, err.Error())
return err
} else {
l.logNames = append(l.logNames, line)
}
}
}
if l.cfg.MaxFileNum > 0 && len(l.logNames) > l.cfg.MaxFileNum {
//remove oldest logfile
if err := l.Purge(len(l.logNames) - l.cfg.MaxFileNum); err != nil {
return err
}
}
var err error
if len(l.logNames) == 0 {
l.lastLogIndex = 1
} else {
lastName := l.logNames[len(l.logNames)-1]
if l.lastLogIndex, err = strconv.ParseInt(path.Ext(lastName)[1:], 10, 64); err != nil {
log.Error("invalid logfile name %s", err.Error())
return err
}
//like mysql, if server restart, a new binlog will create
l.lastLogIndex++
}
return nil
}
示例4: configWatcher
func configWatcher() {
watcher, err := fsnotify.NewWatcher()
if err != nil {
panic("Failed start app watcher: " + err.Error())
}
go func() {
for {
select {
case event := <-watcher.Event:
switch filepath.Ext(event.Name) {
case ".ini":
if checkEventTime(event.Name) {
continue
}
log.Info(event)
if err := Cfg.Reload(); err != nil {
log.Error("Conf Reload: ", err)
}
if err := i18n.ReloadLangs(); err != nil {
log.Error("Conf Reload: ", err)
}
reloadConfig()
log.Info("Config Reloaded")
case ".json":
if checkEventTime(event.Name) {
continue
}
if event.Name == CompressConfPath {
settingCompress()
log.Info("Compress Reloaded")
}
}
}
}
}()
if err := watcher.WatchFlags("conf", fsnotify.FSN_MODIFY); err != nil {
log.Error(err)
}
if err := watcher.WatchFlags("conf/global", fsnotify.FSN_MODIFY); err != nil {
log.Error(err)
}
}
示例5: Post
func (this *BulletinAdminEdit) Post() {
form := bulletin.BulletinAdminForm{Id: int(this.object.Id)}
if this.ValidFormSets(&form) == false {
return
}
// get changed field names
changes := utils.FormChanges(&this.object, &form)
url := fmt.Sprintf("/admin/bulletin/%d", this.object.Id)
// update changed fields only
if len(changes) > 0 {
form.SetToBulletin(&this.object)
if err := models.UpdateById(this.object.Id, this.object, models.Obj2Table(changes)...); err == nil {
this.FlashRedirect(url, 302, "UpdateSuccess")
return
} else {
log.Error(err)
this.Data["Error"] = err
}
} else {
this.Redirect(url, 302)
}
}
示例6: QueryObject
// query object and set to template
func (this *ModelAdminRouter) QueryObject() bool {
id, _ := utils.StrTo(this.Params().Get(":id")).Int()
if id <= 0 {
this.NotFound()
return false
}
var app ModelFinder
if a, ok := this.Ctx.Action().(ModelFinder); ok {
app = a
} else {
panic("ModelAdmin AppController need implement ModelFinder")
}
object := app.Object()
// query object
if err := models.GetById(int64(id), object); err != nil {
this.NotFound()
if err != models.ErrNotExist {
log.Error("SetObject: ", err)
}
return false
} else {
this.Data["Object"] = object
}
return true
}
示例7: Post
// view for update object
func (this *PostAdminEdit) Post() {
form := this.GetForm(false)
if this.ValidFormSets(&form) == false {
return
}
// get changed field names
changes := utils.FormChanges(&this.object, &form)
url := fmt.Sprintf("/admin/post/%d", this.object.Id)
// update changed fields only
if len(changes) > 0 {
//fix the bug of category not updated
changes = append(changes, "Category")
form.SetToPost(&this.object)
if err := models.UpdateById(this.object.Id, this.object, models.Obj2Table(changes)...); err == nil {
this.FlashRedirect(url, 302, "UpdateSuccess")
return
} else {
log.Error(err)
this.Data["Error"] = err
}
} else {
this.Redirect(url, 302)
}
}
示例8: Post
// Reset implemented user password reset.
func (this *ResetRouter) Post() {
code := this.GetString(":code")
this.Data["Code"] = code
var user models.User
if auth.VerifyUserResetPwdCode(&user, code) {
this.Data["Success"] = true
form := auth.ResetPwdForm{}
if this.ValidFormSets(&form) == false {
return
}
user.IsActive = true
user.Rands = models.GetUserSalt()
if err := auth.SaveNewPassword(&user, form.Password); err != nil {
log.Error("ResetPost Save New Password: ", err)
}
if this.IsLogin {
auth.LogoutUser(this.Context, &this.Session)
return
}
this.FlashRedirect("/login", 302, "ResetSuccess")
} else {
this.Data["Success"] = false
}
this.Render("auth/reset.html", this.Data)
}
示例9: Get
// Active implemented check Email actice code.
func (this *RegisterActive) Get() {
// no need active
if this.CheckActiveRedirect(false) {
return
}
code := this.Params().Get(":code")
var user models.User
if auth.VerifyUserActiveCode(&user, code) {
user.IsActive = true
user.Rands = models.GetUserSalt()
if err := models.UpdateById(user.Id, user, models.Obj2Table([]string{"IsActive", "Rands", "Updated"})...); err != nil {
log.Error("Active: user Update ", err)
}
if this.IsLogin {
this.User = user
}
this.Redirect("/active/success", 302)
} else {
this.Data["Success"] = false
}
this.Render("auth/active.html", this.Data)
}
示例10: openNewLogFile
func (l *BinLog) openNewLogFile() error {
var err error
lastName := l.getLogFile()
logPath := path.Join(l.path, lastName)
if l.logFile, err = os.OpenFile(logPath, os.O_CREATE|os.O_WRONLY, 0666); err != nil {
log.Error("open new logfile error %s", err.Error())
return err
}
if l.cfg.MaxFileNum > 0 && len(l.logNames) == l.cfg.MaxFileNum {
l.purge(1)
}
l.logNames = append(l.logNames, lastName)
if l.logWb == nil {
l.logWb = bufio.NewWriterSize(l.logFile, 1024)
} else {
l.logWb.Reset(l.logFile)
}
if err = l.flushIndex(); err != nil {
return err
}
return nil
}
示例11: Get
func (this *BulletinAdminList) Get() {
var bulletins []models.Bulletin
sess := models.ORM().Asc("type")
if err := this.SetObjects(sess, &bulletins); err != nil {
this.Data["Error"] = err
log.Error(err)
}
}
示例12: Get
// view for list model data
func (this *TopicAdminList) Get() {
var topics []models.Topic
sess := models.ORM().Desc("category_id")
if err := this.SetObjects(sess, &topics); err != nil {
this.Data["Error"] = err
log.Error(err)
}
}
示例13: getFileModTime
// getFileModTime retuens unix timestamp of `os.File.ModTime` by given path.
func getFileModTime(path string) int64 {
path = strings.Replace(path, "\\", "/", -1)
f, err := os.Open(path)
if err != nil {
log.Error("Fail to open file[ %s ]\n", err)
return time.Now().Unix()
}
defer f.Close()
fi, err := f.Stat()
if err != nil {
log.Error("Fail to get file information[ %s ]\n", err)
return time.Now().Unix()
}
return fi.ModTime().Unix()
}
示例14: Get
// view for list model data
func (this *PageAdminList) Get() {
var pages []models.Page
sess := models.ORM().NewSession()
defer sess.Close()
if err := this.SetObjects(sess, &pages); err != nil {
this.Data["Error"] = err
log.Error(err)
}
}
示例15: FlushAll
func (l *Nodb) FlushAll() error {
for index, db := range l.dbs {
if _, err := db.FlushAll(); err != nil {
log.Error("flush db %d error %s", index, err.Error())
}
}
return nil
}