|
|
@ -6,6 +6,7 @@ package routes |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"encoding/gob" |
|
|
|
"encoding/gob" |
|
|
|
|
|
|
|
"fmt" |
|
|
|
"net/http" |
|
|
|
"net/http" |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
"path" |
|
|
|
"path" |
|
|
@ -45,13 +46,35 @@ import ( |
|
|
|
macaron "gopkg.in/macaron.v1" |
|
|
|
macaron "gopkg.in/macaron.v1" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func giteaLogger(l *log.LoggerAsWriter) macaron.Handler { |
|
|
|
|
|
|
|
return func(ctx *macaron.Context) { |
|
|
|
|
|
|
|
start := time.Now() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
l.Log(fmt.Sprintf("[Macaron] Started %s %s for %s", ctx.Req.Method, ctx.Req.RequestURI, ctx.RemoteAddr())) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ctx.Next() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rw := ctx.Resp.(macaron.ResponseWriter) |
|
|
|
|
|
|
|
l.Log(fmt.Sprintf("[Macaron] Completed %s %s %v %s in %v", ctx.Req.Method, ctx.Req.RequestURI, rw.Status(), http.StatusText(rw.Status()), time.Since(start))) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// NewMacaron initializes Macaron instance.
|
|
|
|
// NewMacaron initializes Macaron instance.
|
|
|
|
func NewMacaron() *macaron.Macaron { |
|
|
|
func NewMacaron() *macaron.Macaron { |
|
|
|
gob.Register(&u2f.Challenge{}) |
|
|
|
gob.Register(&u2f.Challenge{}) |
|
|
|
m := macaron.New() |
|
|
|
var m *macaron.Macaron |
|
|
|
|
|
|
|
if setting.RedirectMacaronLog { |
|
|
|
|
|
|
|
loggerAsWriter := log.NewLoggerAsWriter("INFO") |
|
|
|
|
|
|
|
m = macaron.NewWithLogger(loggerAsWriter) |
|
|
|
|
|
|
|
if !setting.DisableRouterLog { |
|
|
|
|
|
|
|
m.Use(giteaLogger(loggerAsWriter)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
m = macaron.New() |
|
|
|
if !setting.DisableRouterLog { |
|
|
|
if !setting.DisableRouterLog { |
|
|
|
m.Use(macaron.Logger()) |
|
|
|
m.Use(macaron.Logger()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
m.Use(macaron.Recovery()) |
|
|
|
m.Use(macaron.Recovery()) |
|
|
|
if setting.EnableGzip { |
|
|
|
if setting.EnableGzip { |
|
|
|
m.Use(gzip.Middleware()) |
|
|
|
m.Use(gzip.Middleware()) |
|
|
|