Add log.handle
This commit is contained in:
parent
15f8bc417e
commit
1ce17cce76
6 changed files with 16 additions and 36 deletions
|
@ -6,6 +6,8 @@
|
||||||
package log
|
package log
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"github.com/martini-contrib/render"
|
"github.com/martini-contrib/render"
|
||||||
|
|
||||||
"github.com/gogits/logs"
|
"github.com/gogits/logs"
|
||||||
|
@ -40,8 +42,8 @@ func Critical(format string, v ...interface{}) {
|
||||||
logger.Critical(format, v...)
|
logger.Critical(format, v...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Handle(status int, title, tmpl string, data base.TmplData, r render.Render, err error) {
|
func Handle(status int, title string, data base.TmplData, r render.Render, err error) {
|
||||||
data["ErrorMsg"] = err
|
data["ErrorMsg"] = err
|
||||||
Error("%s: %v", title, err)
|
Error("%s: %v", title, err)
|
||||||
r.HTML(status, tmpl, data)
|
r.HTML(status, fmt.Sprintf("status/%d", status), data)
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ func Create(form auth.CreateRepoForm, req *http.Request, r render.Render, data b
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Handle(200, "repo.Create", "base/error", data, r, err)
|
log.Handle(200, "repo.Create", data, r, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Delete(form auth.DeleteRepoForm, req *http.Request, r render.Render, data base.TmplData, session sessions.Session) {
|
func Delete(form auth.DeleteRepoForm, req *http.Request, r render.Render, data base.TmplData, session sessions.Session) {
|
||||||
|
@ -76,9 +76,7 @@ func Delete(form auth.DeleteRepoForm, req *http.Request, r render.Render, data b
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := models.DeleteRepository(form.UserId, form.RepoId, form.UserName); err != nil {
|
if err := models.DeleteRepository(form.UserId, form.RepoId, form.UserName); err != nil {
|
||||||
data["ErrorMsg"] = err
|
log.Handle(200, "repo.Delete", data, r, err)
|
||||||
log.Error("repo.Delete: %v", err)
|
|
||||||
r.HTML(200, "base/error", data)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,9 +93,7 @@ func List(req *http.Request, r render.Render, data base.TmplData, session sessio
|
||||||
data["Title"] = "Repositories"
|
data["Title"] = "Repositories"
|
||||||
repos, err := models.GetRepositories(u)
|
repos, err := models.GetRepositories(u)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
data["ErrorMsg"] = err
|
log.Handle(200, "repo.List", data, r, err)
|
||||||
log.Error("repo.List: %v", err)
|
|
||||||
r.HTML(200, "base/error", data)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,7 @@ func Single(params martini.Params, r render.Render, data base.TmplData) {
|
||||||
|
|
||||||
files, err := models.GetReposFiles(params["username"], params["reponame"], "HEAD", "/")
|
files, err := models.GetReposFiles(params["username"], params["reponame"], "HEAD", "/")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
data["ErrorMsg"] = err
|
log.Handle(200, "repo.Single", data, r, err)
|
||||||
log.Error("repo.List: %v", err)
|
|
||||||
r.HTML(200, "base/error", data)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,9 +40,7 @@ func Setting(form auth.UpdateProfileForm, r render.Render, data base.TmplData, r
|
||||||
user.Avatar = base.EncodeMd5(form.Avatar)
|
user.Avatar = base.EncodeMd5(form.Avatar)
|
||||||
user.AvatarEmail = form.Avatar
|
user.AvatarEmail = form.Avatar
|
||||||
if err := models.UpdateUser(user); err != nil {
|
if err := models.UpdateUser(user); err != nil {
|
||||||
data["ErrorMsg"] = err
|
log.Handle(200, "setting.Setting", data, r, err)
|
||||||
log.Error("setting.Setting: %v", err)
|
|
||||||
r.HTML(200, "base/error", data)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,9 +60,7 @@ func SettingPassword(form auth.UpdatePasswdForm, r render.Render, data base.Tmpl
|
||||||
user := auth.SignedInUser(session)
|
user := auth.SignedInUser(session)
|
||||||
newUser := &models.User{Passwd: form.NewPasswd}
|
newUser := &models.User{Passwd: form.NewPasswd}
|
||||||
if err := newUser.EncodePasswd(); err != nil {
|
if err := newUser.EncodePasswd(); err != nil {
|
||||||
data["ErrorMsg"] = err
|
log.Handle(200, "setting.SettingPassword", data, r, err)
|
||||||
log.Error("setting.UpdatePasswd: %v", err)
|
|
||||||
r.HTML(200, "base/error", data)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,9 +73,7 @@ func SettingPassword(form auth.UpdatePasswdForm, r render.Render, data base.Tmpl
|
||||||
} else {
|
} else {
|
||||||
user.Passwd = newUser.Passwd
|
user.Passwd = newUser.Passwd
|
||||||
if err := models.UpdateUser(user); err != nil {
|
if err := models.UpdateUser(user); err != nil {
|
||||||
data["ErrorMsg"] = err
|
log.Handle(200, "setting.SettingPassword", data, r, err)
|
||||||
log.Error("setting.UpdatePasswd: %v", err)
|
|
||||||
r.HTML(200, "base/error", data)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data["IsSuccess"] = true
|
data["IsSuccess"] = true
|
||||||
|
|
|
@ -22,9 +22,7 @@ func Dashboard(r render.Render, data base.TmplData, session sessions.Session) {
|
||||||
data["PageIsUserDashboard"] = true
|
data["PageIsUserDashboard"] = true
|
||||||
repos, err := models.GetRepositories(&models.User{Id: auth.SignedInId(session)})
|
repos, err := models.GetRepositories(&models.User{Id: auth.SignedInId(session)})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
data["ErrorMsg"] = err
|
log.Handle(200, "user.Dashboard", data, r, err)
|
||||||
log.Error("dashboard: %v", err)
|
|
||||||
r.HTML(200, "base/error", data)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
data["MyRepos"] = repos
|
data["MyRepos"] = repos
|
||||||
|
@ -37,9 +35,7 @@ func Profile(params martini.Params, r render.Render, data base.TmplData, session
|
||||||
// TODO: Need to check view self or others.
|
// TODO: Need to check view self or others.
|
||||||
user, err := models.GetUserByName(params["username"])
|
user, err := models.GetUserByName(params["username"])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
data["ErrorMsg"] = err
|
log.Handle(200, "user.Profile", data, r, err)
|
||||||
log.Error("user.Profile: %v", err)
|
|
||||||
r.HTML(200, "base/error", data)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,9 +66,7 @@ func SignIn(form auth.LogInForm, data base.TmplData, req *http.Request, r render
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
data["ErrorMsg"] = err
|
log.Handle(200, "user.SignIn", data, r, err)
|
||||||
log.Error("user.SignIn: %v", err)
|
|
||||||
r.HTML(200, "base/error", data)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,9 +123,7 @@ func SignUp(form auth.RegisterForm, data base.TmplData, req *http.Request, r ren
|
||||||
data["ErrorMsg"] = "E-mail address has been already used"
|
data["ErrorMsg"] = "E-mail address has been already used"
|
||||||
r.HTML(200, "user/signup", data)
|
r.HTML(200, "user/signup", data)
|
||||||
default:
|
default:
|
||||||
data["ErrorMsg"] = err
|
log.Handle(200, "user.SignUp", data, r, err)
|
||||||
log.Error("user.SignUp: %v", data)
|
|
||||||
r.HTML(200, "base/error", nil)
|
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -155,9 +147,7 @@ func Delete(data base.TmplData, req *http.Request, session sessions.Session, r r
|
||||||
case models.ErrUserOwnRepos.Error():
|
case models.ErrUserOwnRepos.Error():
|
||||||
data["ErrorMsg"] = "Your account still have ownership of repository, you have to delete or transfer them first."
|
data["ErrorMsg"] = "Your account still have ownership of repository, you have to delete or transfer them first."
|
||||||
default:
|
default:
|
||||||
data["ErrorMsg"] = err
|
log.Handle(200, "user.Delete", data, r, err)
|
||||||
log.Error("user.Delete: %v", data)
|
|
||||||
r.HTML(200, "base/error", nil)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue