Use toolbox
This commit is contained in:
parent
6fc2107529
commit
a8e05fdf1b
7 changed files with 33 additions and 30 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -33,6 +33,7 @@ _testmain.go
|
||||||
*.exe
|
*.exe
|
||||||
*.exe~
|
*.exe~
|
||||||
/gogs
|
/gogs
|
||||||
|
profile/
|
||||||
__pycache__
|
__pycache__
|
||||||
*.pem
|
*.pem
|
||||||
output*
|
output*
|
||||||
|
|
19
cmd/web.go
19
cmd/web.go
|
@ -19,7 +19,9 @@ import (
|
||||||
"github.com/macaron-contrib/csrf"
|
"github.com/macaron-contrib/csrf"
|
||||||
"github.com/macaron-contrib/i18n"
|
"github.com/macaron-contrib/i18n"
|
||||||
"github.com/macaron-contrib/session"
|
"github.com/macaron-contrib/session"
|
||||||
|
"github.com/macaron-contrib/toolbox"
|
||||||
|
|
||||||
|
"github.com/gogits/gogs/models"
|
||||||
"github.com/gogits/gogs/modules/auth"
|
"github.com/gogits/gogs/modules/auth"
|
||||||
"github.com/gogits/gogs/modules/auth/apiv1"
|
"github.com/gogits/gogs/modules/auth/apiv1"
|
||||||
"github.com/gogits/gogs/modules/avatar"
|
"github.com/gogits/gogs/modules/avatar"
|
||||||
|
@ -62,20 +64,20 @@ func newMacaron() *macaron.Macaron {
|
||||||
m := macaron.New()
|
m := macaron.New()
|
||||||
m.Use(macaron.Logger())
|
m.Use(macaron.Logger())
|
||||||
m.Use(macaron.Recovery())
|
m.Use(macaron.Recovery())
|
||||||
if setting.EnableGzip {
|
|
||||||
m.Use(macaron.Gzip())
|
|
||||||
}
|
|
||||||
m.Use(macaron.Static("public",
|
m.Use(macaron.Static("public",
|
||||||
macaron.StaticOptions{
|
macaron.StaticOptions{
|
||||||
SkipLogging: !setting.DisableRouterLog,
|
SkipLogging: !setting.DisableRouterLog,
|
||||||
},
|
},
|
||||||
))
|
))
|
||||||
|
if setting.EnableGzip {
|
||||||
|
m.Use(macaron.Gzip())
|
||||||
|
}
|
||||||
m.Use(macaron.Renderer(macaron.RenderOptions{
|
m.Use(macaron.Renderer(macaron.RenderOptions{
|
||||||
Directory: path.Join(setting.StaticRootPath, "templates"),
|
Directory: path.Join(setting.StaticRootPath, "templates"),
|
||||||
Funcs: []template.FuncMap{base.TemplateFuncs},
|
Funcs: []template.FuncMap{base.TemplateFuncs},
|
||||||
IndentJSON: macaron.Env != macaron.PROD,
|
IndentJSON: macaron.Env != macaron.PROD,
|
||||||
}))
|
}))
|
||||||
m.Use(i18n.I18n(i18n.LocaleOptions{
|
m.Use(i18n.I18n(i18n.Options{
|
||||||
Langs: setting.Langs,
|
Langs: setting.Langs,
|
||||||
Names: setting.Names,
|
Names: setting.Names,
|
||||||
Redirect: true,
|
Redirect: true,
|
||||||
|
@ -95,6 +97,14 @@ func newMacaron() *macaron.Macaron {
|
||||||
SetCookie: true,
|
SetCookie: true,
|
||||||
}))
|
}))
|
||||||
m.Use(middleware.Contexter())
|
m.Use(middleware.Contexter())
|
||||||
|
m.Use(toolbox.Toolboxer(m, toolbox.Options{
|
||||||
|
HealthCheckFuncs: []*toolbox.HealthCheckFuncDesc{
|
||||||
|
&toolbox.HealthCheckFuncDesc{
|
||||||
|
Desc: "Database connection",
|
||||||
|
Func: models.Ping,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}))
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,7 +218,6 @@ func runWeb(*cli.Context) {
|
||||||
|
|
||||||
if macaron.Env == macaron.DEV {
|
if macaron.Env == macaron.DEV {
|
||||||
m.Get("/template/*", dev.TemplatePreview)
|
m.Get("/template/*", dev.TemplatePreview)
|
||||||
dev.RegisterDebugRoutes(m)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
reqTrueOwner := middleware.RequireTrueOwner()
|
reqTrueOwner := middleware.RequireTrueOwner()
|
||||||
|
|
2
gogs.go
2
gogs.go
|
@ -17,7 +17,7 @@ import (
|
||||||
"github.com/gogits/gogs/modules/setting"
|
"github.com/gogits/gogs/modules/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
const APP_VER = "0.4.7.0805 Alpha"
|
const APP_VER = "0.4.7.0806 Alpha"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
runtime.GOMAXPROCS(runtime.NumCPU())
|
runtime.GOMAXPROCS(runtime.NumCPU())
|
||||||
|
|
|
@ -165,6 +165,10 @@ func GetStatistic() (stats Statistic) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Ping() error {
|
||||||
|
return x.Ping()
|
||||||
|
}
|
||||||
|
|
||||||
// DumpDatabase dumps all data from database to file system.
|
// DumpDatabase dumps all data from database to file system.
|
||||||
func DumpDatabase(filePath string) error {
|
func DumpDatabase(filePath string) error {
|
||||||
return x.DumpAllToFile(filePath)
|
return x.DumpAllToFile(filePath)
|
||||||
|
|
|
@ -1,18 +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 dev
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http/pprof"
|
|
||||||
|
|
||||||
"github.com/Unknwon/macaron"
|
|
||||||
)
|
|
||||||
|
|
||||||
func RegisterDebugRoutes(r *macaron.Macaron) {
|
|
||||||
r.Any("/debug/pprof/cmdline", pprof.Cmdline)
|
|
||||||
r.Any("/debug/pprof/profile", pprof.Profile)
|
|
||||||
r.Any("/debug/pprof/symbol", pprof.Symbol)
|
|
||||||
r.Any("/debug/pprof/*", pprof.Index)
|
|
||||||
}
|
|
|
@ -119,12 +119,19 @@ func Profile(ctx *middleware.Context) {
|
||||||
ctx.Data["Title"] = "Profile"
|
ctx.Data["Title"] = "Profile"
|
||||||
ctx.Data["PageIsUserProfile"] = true
|
ctx.Data["PageIsUserProfile"] = true
|
||||||
|
|
||||||
u, err := models.GetUserByName(ctx.Params(":username"))
|
uname := ctx.Params(":username")
|
||||||
|
// Special handle for FireFox requests favicon.ico.
|
||||||
|
if uname == "favicon.ico" {
|
||||||
|
ctx.Redirect("/img/favicon.png")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
u, err := models.GetUserByName(uname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == models.ErrUserNotExist {
|
if err == models.ErrUserNotExist {
|
||||||
ctx.Handle(404, "user.Profile(GetUserByName)", err)
|
ctx.Handle(404, "GetUserByName", err)
|
||||||
} else {
|
} else {
|
||||||
ctx.Handle(500, "user.Profile(GetUserByName)", err)
|
ctx.Handle(500, "GetUserByName", err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -146,13 +153,13 @@ func Profile(ctx *middleware.Context) {
|
||||||
case "activity":
|
case "activity":
|
||||||
ctx.Data["Feeds"], err = models.GetFeeds(u.Id, 0, true)
|
ctx.Data["Feeds"], err = models.GetFeeds(u.Id, 0, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "user.Profile(GetFeeds)", err)
|
ctx.Handle(500, "GetFeeds", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
ctx.Data["Repos"], err = models.GetRepositories(u.Id, ctx.IsSigned && ctx.User.Id == u.Id)
|
ctx.Data["Repos"], err = models.GetRepositories(u.Id, ctx.IsSigned && ctx.User.Id == u.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Handle(500, "user.Profile(GetRepositories)", err)
|
ctx.Handle(500, "GetRepositories", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
0.4.7.0805 Alpha
|
0.4.7.0806 Alpha
|
Loading…
Reference in a new issue