diff options
author | Unknown <joe2010xtmf@163.com> | 2014-03-21 01:48:10 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-03-21 01:48:10 -0400 |
commit | f6596f11c4aacd3c7c30098f7ffe79e936d21583 (patch) | |
tree | aad5d5017b03d530e6c69ea474266fecea86d0e2 | |
parent | 369ddf76a8ae6916ab72f1fa26c81b44c456c6ea (diff) | |
download | gitea-f6596f11c4aacd3c7c30098f7ffe79e936d21583.tar.gz gitea-f6596f11c4aacd3c7c30098f7ffe79e936d21583.zip |
All configuration reload-able
-rw-r--r-- | README.md | 1 | ||||
-rw-r--r-- | models/models.go | 39 | ||||
-rw-r--r-- | models/models_test.go | 3 | ||||
-rw-r--r-- | models/repo.go | 4 | ||||
-rw-r--r-- | modules/base/conf.go | 2 | ||||
-rw-r--r-- | modules/mailer/mailer.go | 2 | ||||
-rw-r--r-- | routers/admin/admin.go | 10 | ||||
-rw-r--r-- | templates/admin/config.tmpl | 17 | ||||
-rw-r--r-- | templates/admin/dashboard.tmpl | 9 | ||||
-rw-r--r-- | templates/admin/nav.tmpl | 8 | ||||
-rw-r--r-- | templates/admin/repos.tmpl | 9 | ||||
-rw-r--r-- | templates/admin/users.tmpl | 9 | ||||
-rw-r--r-- | web.go | 20 |
13 files changed, 88 insertions, 45 deletions
@@ -28,6 +28,7 @@ There are some very good products in this category such as [gitlab](http://gitla - Repository viewer. - Gravatar support. - Mail service(register). +- Administration panel. - Supports MySQL, PostgreSQL and SQLite3(binary release only). ## Installation diff --git a/models/models.go b/models/models.go index 8df230975f..bb0015d3de 100644 --- a/models/models.go +++ b/models/models.go @@ -16,30 +16,39 @@ import ( "github.com/gogits/gogs/modules/base" ) -var orm *xorm.Engine +var ( + orm *xorm.Engine + + dbCfg struct { + Type, Host, Name, User, Pwd, Path, SslMode string + } +) + +func LoadModelsConfig() { + dbCfg.Type = base.Cfg.MustValue("database", "DB_TYPE") + dbCfg.Host = base.Cfg.MustValue("database", "HOST") + dbCfg.Name = base.Cfg.MustValue("database", "NAME") + dbCfg.User = base.Cfg.MustValue("database", "USER") + dbCfg.Pwd = base.Cfg.MustValue("database", "PASSWD") + dbCfg.Path = base.Cfg.MustValue("database", "PATH", "data/gogs.db") + dbCfg.SslMode = base.Cfg.MustValue("database", "SSL_MODE") +} func setEngine() { - dbType := base.Cfg.MustValue("database", "DB_TYPE") - dbHost := base.Cfg.MustValue("database", "HOST") - dbName := base.Cfg.MustValue("database", "NAME") - dbUser := base.Cfg.MustValue("database", "USER") - dbPwd := base.Cfg.MustValue("database", "PASSWD") - dbPath := base.Cfg.MustValue("database", "PATH", "data/gogs.db") - sslMode := base.Cfg.MustValue("database", "SSL_MODE") var err error - switch dbType { + switch dbCfg.Type { case "mysql": orm, err = xorm.NewEngine("mysql", fmt.Sprintf("%s:%s@%s/%s?charset=utf8", - dbUser, dbPwd, dbHost, dbName)) + dbCfg.User, dbCfg.Pwd, dbCfg.Host, dbCfg.Name)) case "postgres": orm, err = xorm.NewEngine("postgres", fmt.Sprintf("user=%s password=%s dbname=%s sslmode=%s", - dbUser, dbPwd, dbName, sslMode)) + dbCfg.User, dbCfg.Pwd, dbCfg.Name, dbCfg.SslMode)) case "sqlite3": - os.MkdirAll(path.Dir(dbPath), os.ModePerm) - orm, err = xorm.NewEngine("sqlite3", dbPath) + os.MkdirAll(path.Dir(dbCfg.Path), os.ModePerm) + orm, err = xorm.NewEngine("sqlite3", dbCfg.Path) default: - fmt.Printf("Unknown database type: %s\n", dbType) + fmt.Printf("Unknown database type: %s\n", dbCfg.Type) os.Exit(2) } if err != nil { @@ -61,7 +70,7 @@ func setEngine() { orm.ShowSQL = true } -func init() { +func NewEngine() { setEngine() if err := orm.Sync(new(User), new(PublicKey), new(Repository), new(Watch), new(Action), new(Access)); err != nil { diff --git a/models/models_test.go b/models/models_test.go index c44ef476c6..d0f734d678 100644 --- a/models/models_test.go +++ b/models/models_test.go @@ -13,6 +13,9 @@ import ( ) func init() { + LoadModelsConfig() + NewEngine() + var err error orm, err = xorm.NewEngine("sqlite3", "./test.db") if err != nil { diff --git a/models/repo.go b/models/repo.go index 93f68ceddf..f252004785 100644 --- a/models/repo.go +++ b/models/repo.go @@ -41,10 +41,12 @@ var ( LanguageIgns, Licenses []string ) -func init() { +func LoadRepoConfig() { LanguageIgns = strings.Split(base.Cfg.MustValue("repository", "LANG_IGNS"), "|") Licenses = strings.Split(base.Cfg.MustValue("repository", "LICENSES"), "|") +} +func NewRepoContext() { zip.Verbose = false // Check if server has basic git setting. diff --git a/modules/base/conf.go b/modules/base/conf.go index 41b66b69f8..42d50da4f3 100644 --- a/modules/base/conf.go +++ b/modules/base/conf.go @@ -148,7 +148,7 @@ func newRegisterMailService() { log.Info("Register Mail Service Enabled") } -func init() { +func NewConfigContext() { var err error workDir, err := exeDir() if err != nil { diff --git a/modules/mailer/mailer.go b/modules/mailer/mailer.go index 150607f8c4..da63e01d2a 100644 --- a/modules/mailer/mailer.go +++ b/modules/mailer/mailer.go @@ -40,7 +40,7 @@ func (m Message) Content() string { var mailQueue chan *Message -func init() { +func NewMailerContext() { mailQueue = make(chan *Message, base.Cfg.MustInt("mailer", "SEND_BUFFER_LEN", 10)) go processMailQueue() } diff --git a/routers/admin/admin.go b/routers/admin/admin.go index a37f1207c9..1095a599b9 100644 --- a/routers/admin/admin.go +++ b/routers/admin/admin.go @@ -11,12 +11,14 @@ import ( func Dashboard(ctx *middleware.Context) { ctx.Data["Title"] = "Admin Dashboard" + ctx.Data["PageIsDashboard"] = true ctx.Data["Stats"] = models.GetStatistic() ctx.HTML(200, "admin/dashboard") } func Users(ctx *middleware.Context) { ctx.Data["Title"] = "User Management" + ctx.Data["PageIsUsers"] = true var err error ctx.Data["Users"], err = models.GetUsers(100, 0) @@ -29,6 +31,8 @@ func Users(ctx *middleware.Context) { func Repositories(ctx *middleware.Context) { ctx.Data["Title"] = "Repository Management" + ctx.Data["PageIsRepos"] = true + var err error ctx.Data["Repos"], err = models.GetRepos(100, 0) if err != nil { @@ -37,3 +41,9 @@ func Repositories(ctx *middleware.Context) { } ctx.HTML(200, "admin/repos") } + +func Config(ctx *middleware.Context) { + ctx.Data["Title"] = "Server Configuration" + ctx.Data["PageIsConfig"] = true + ctx.HTML(200, "admin/config") +} diff --git a/templates/admin/config.tmpl b/templates/admin/config.tmpl new file mode 100644 index 0000000000..d209bcdfd9 --- /dev/null +++ b/templates/admin/config.tmpl @@ -0,0 +1,17 @@ +{{template "base/head" .}} +{{template "base/navbar" .}} +<div id="gogs-body" class="container" data-page="admin"> + {{template "admin/nav" .}} + <div id="gogs-admin-container" class="col-md-9"> + <div class="panel panel-default"> + <div class="panel-heading"> + Server Configuration + </div> + + <div class="panel-body"> + + </div> + </div> + </div> +</div> +{{template "base/footer" .}}
\ No newline at end of file diff --git a/templates/admin/dashboard.tmpl b/templates/admin/dashboard.tmpl index 6a914b65f7..8950f50cac 100644 --- a/templates/admin/dashboard.tmpl +++ b/templates/admin/dashboard.tmpl @@ -1,14 +1,7 @@ {{template "base/head" .}} {{template "base/navbar" .}} <div id="gogs-body" class="container" data-page="admin"> - <div id="gogs-user-setting-nav" class="col-md-3"> - <ul class="list-group" data-init="tabs"> - <li class="list-group-item active"><a href="/admin"><i class="fa fa-tachometer fa-lg"></i> Dashboard</a></li> - <li class="list-group-item"><a href="/admin/users"><i class="fa fa-users fa-lg"></i> Users</a></li> - <li class="list-group-item"><a href="/admin/repos"><i class="fa fa-book fa-lg"></i> Repositories</a></li> - </ul> - </div> - + {{template "admin/nav" .}} <div id="gogs-admin-container" class="col-md-9"> <div class="panel panel-default"> <div class="panel-heading"> diff --git a/templates/admin/nav.tmpl b/templates/admin/nav.tmpl new file mode 100644 index 0000000000..bb704ee3fb --- /dev/null +++ b/templates/admin/nav.tmpl @@ -0,0 +1,8 @@ +<div id="gogs-user-setting-nav" class="col-md-3"> + <ul class="list-group" data-init="tabs"> + <li class="list-group-item{{if .PageIsDashboard}} active{{end}}"><a href="/admin"><i class="fa fa-tachometer fa-lg"></i> Dashboard</a></li> + <li class="list-group-item{{if .PageIsUsers}} active{{end}}"><a href="/admin/users"><i class="fa fa-users fa-lg"></i> Users</a></li> + <li class="list-group-item{{if .PageIsRepos}} active{{end}}"><a href="/admin/repos"><i class="fa fa-book fa-lg"></i> Repositories</a></li> + <li class="list-group-item{{if .PageIsConfig}} active{{end}}"><a href="/admin/config"><i class="fa fa-cogs fa-lg"></i> Configuration</a></li> + </ul> +</div>
\ No newline at end of file diff --git a/templates/admin/repos.tmpl b/templates/admin/repos.tmpl index f4834c9060..a1f41d8365 100644 --- a/templates/admin/repos.tmpl +++ b/templates/admin/repos.tmpl @@ -1,14 +1,7 @@ {{template "base/head" .}} {{template "base/navbar" .}} <div id="gogs-body" class="container" data-page="admin"> - <div id="gogs-user-setting-nav" class="col-md-3"> - <ul class="list-group" data-init="tabs"> - <li class="list-group-item"><a href="/admin"><i class="fa fa-tachometer fa-lg"></i> Dashboard</a></li> - <li class="list-group-item"><a href="/admin/users"><i class="fa fa-users fa-lg"></i> Users</a></li> - <li class="list-group-item active"><a href="/admin/repos"><i class="fa fa-book fa-lg"></i> Repositories</a></li> - </ul> - </div> - + {{template "admin/nav" .}} <div id="gogs-admin-container" class="col-md-9"> <div class="panel panel-default"> <div class="panel-heading"> diff --git a/templates/admin/users.tmpl b/templates/admin/users.tmpl index b690e1771e..ae2b5bbb65 100644 --- a/templates/admin/users.tmpl +++ b/templates/admin/users.tmpl @@ -1,14 +1,7 @@ {{template "base/head" .}} {{template "base/navbar" .}} <div id="gogs-body" class="container" data-page="admin"> - <div id="gogs-user-setting-nav" class="col-md-3"> - <ul class="list-group" data-init="tabs"> - <li class="list-group-item"><a href="/admin"><i class="fa fa-tachometer fa-lg"></i> Dashboard</a></li> - <li class="list-group-item active"><a href="/admin/users"><i class="fa fa-users fa-lg"></i> Users</a></li> - <li class="list-group-item"><a href="/admin/repos"><i class="fa fa-book fa-lg"></i> Repositories</a></li> - </ul> - </div> - + {{template "admin/nav" .}} <div id="gogs-admin-container" class="col-md-9"> <div class="panel panel-default"> <div class="panel-heading"> @@ -16,9 +16,11 @@ import ( "github.com/gogits/binding" + "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/log" + "github.com/gogits/gogs/modules/mailer" "github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/routers" "github.com/gogits/gogs/routers/admin" @@ -36,6 +38,16 @@ gogs web`, Flags: []cli.Flag{}, } +// globalInit is for global configuration reload-able. +func globalInit() { + base.NewConfigContext() + mailer.NewMailerContext() + models.LoadModelsConfig() + models.LoadRepoConfig() + models.NewRepoContext() + models.NewEngine() +} + // Check run mode(Default of martini is Dev). func checkRunMode() { switch base.Cfg.MustValue("", "RUN_MODE") { @@ -59,6 +71,7 @@ func newMartini() *martini.ClassicMartini { } func runWeb(*cli.Context) { + globalInit() base.NewServices() checkRunMode() log.Info("%s %s", base.AppName, base.AppVer) @@ -101,9 +114,10 @@ func runWeb(*cli.Context) { m.Get("/help", routers.Help) adminReq := middleware.AdminRequire() - m.Any("/admin", reqSignIn, adminReq, admin.Dashboard) - m.Any("/admin/users", reqSignIn, adminReq, admin.Users) - m.Any("/admin/repos", reqSignIn, adminReq, admin.Repositories) + m.Get("/admin", reqSignIn, adminReq, admin.Dashboard) + m.Get("/admin/users", reqSignIn, adminReq, admin.Users) + m.Get("/admin/repos", reqSignIn, adminReq, admin.Repositories) + m.Get("/admin/config", reqSignIn, adminReq, admin.Config) m.Post("/:username/:reponame/settings", reqSignIn, middleware.RepoAssignment(true), repo.SettingPost) m.Get("/:username/:reponame/settings", reqSignIn, middleware.RepoAssignment(true), repo.Setting) |