mirror of
https://codeberg.org/forgejo/forgejo
synced 2024-11-25 19:26:09 +01:00
Add log.handle
This commit is contained in:
parent
56cf05be77
commit
15f8bc417e
|
@ -1,32 +0,0 @@
|
|||
// Copyright 2014 The Gogs Authors. All rights reserved.
|
||||
// Use of this source code is governed by a MIT-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package log
|
||||
|
||||
import (
|
||||
"github.com/codegangsta/martini"
|
||||
"github.com/martini-contrib/render"
|
||||
)
|
||||
|
||||
// ErrHandler is an interface for custom error handler.
|
||||
type ErrHandler interface {
|
||||
Handle(string, render.Render, error)
|
||||
}
|
||||
|
||||
// ErrHandle is a Middleware that maps a ErrHandler service into the Martini handler chain.
|
||||
func ErrHandle() martini.Handler {
|
||||
return func(context martini.Context) {
|
||||
context.MapTo(&errHandler{}, (*ErrHandler)(nil))
|
||||
}
|
||||
}
|
||||
|
||||
type errHandler struct {
|
||||
}
|
||||
|
||||
func (eh *errHandler) Handle(title string, r render.Render, err error) {
|
||||
Error("%s: %v", title, err)
|
||||
r.HTML(200, "base/error", map[string]interface{}{
|
||||
"ErrorMsg": err,
|
||||
})
|
||||
}
|
|
@ -6,7 +6,11 @@
|
|||
package log
|
||||
|
||||
import (
|
||||
"github.com/martini-contrib/render"
|
||||
|
||||
"github.com/gogits/logs"
|
||||
|
||||
"github.com/gogits/gogs/modules/base"
|
||||
)
|
||||
|
||||
var logger *logs.BeeLogger
|
||||
|
@ -35,3 +39,9 @@ func Warn(format string, v ...interface{}) {
|
|||
func Critical(format string, v ...interface{}) {
|
||||
logger.Critical(format, v...)
|
||||
}
|
||||
|
||||
func Handle(status int, title, tmpl string, data base.TmplData, r render.Render, err error) {
|
||||
data["ErrorMsg"] = err
|
||||
Error("%s: %v", title, err)
|
||||
r.HTML(status, tmpl, data)
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ import (
|
|||
"github.com/gogits/gogs/modules/log"
|
||||
)
|
||||
|
||||
func Create(form auth.CreateRepoForm, req *http.Request, r render.Render, data base.TmplData, session sessions.Session, eh log.ErrHandler) {
|
||||
func Create(form auth.CreateRepoForm, req *http.Request, r render.Render, data base.TmplData, session sessions.Session) {
|
||||
data["Title"] = "Create repository"
|
||||
|
||||
if req.Method == "GET" {
|
||||
|
@ -64,7 +64,7 @@ func Create(form auth.CreateRepoForm, req *http.Request, r render.Render, data b
|
|||
return
|
||||
}
|
||||
|
||||
eh.Handle("repo.Create", r, err)
|
||||
log.Handle(200, "repo.Create", "base/error", data, r, err)
|
||||
}
|
||||
|
||||
func Delete(form auth.DeleteRepoForm, req *http.Request, r render.Render, data base.TmplData, session sessions.Session) {
|
||||
|
|
1
web.go
1
web.go
|
@ -50,7 +50,6 @@ func runWeb(*cli.Context) {
|
|||
// Middlewares.
|
||||
m.Use(render.Renderer(render.Options{Funcs: []template.FuncMap{AppHelpers}}))
|
||||
m.Use(base.InitContext())
|
||||
m.Use(log.ErrHandle())
|
||||
|
||||
// TODO: should use other store because cookie store is not secure.
|
||||
store := sessions.NewCookieStore([]byte("secret123"))
|
||||
|
|
Loading…
Reference in a new issue