diff options
author | Unknown <joe2010xtmf@163.com> | 2014-05-25 20:11:25 -0400 |
---|---|---|
committer | Unknown <joe2010xtmf@163.com> | 2014-05-25 20:11:25 -0400 |
commit | 688ec6ecbdf0e1c450aa93fdc4d760c4ae63a73f (patch) | |
tree | 8adb59c369d1fe1bd41ae7be38785dc613a29a91 /cmd | |
parent | 87854c95a90cf1bebe1bffb833389471fb35f234 (diff) | |
download | gitea-688ec6ecbdf0e1c450aa93fdc4d760c4ae63a73f.tar.gz gitea-688ec6ecbdf0e1c450aa93fdc4d760c4ae63a73f.zip |
Fixed #209
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/dump.go | 18 | ||||
-rw-r--r-- | cmd/fix.go | 10 | ||||
-rw-r--r-- | cmd/serve.go | 12 | ||||
-rw-r--r-- | cmd/web.go | 40 |
4 files changed, 40 insertions, 40 deletions
diff --git a/cmd/dump.go b/cmd/dump.go index 1bac1aeeb2..2a54db1a87 100644 --- a/cmd/dump.go +++ b/cmd/dump.go @@ -15,7 +15,7 @@ import ( "github.com/codegangsta/cli" "github.com/gogits/gogs/models" - "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/modules/setting" ) var CmdDump = cli.Command{ @@ -28,14 +28,14 @@ It can be used for backup and capture Gogs server image to send to maintainer`, } func runDump(*cli.Context) { - base.NewConfigContext() + setting.NewConfigContext() models.LoadModelsConfig() models.SetEngine() - log.Printf("Dumping local repositories...%s", base.RepoRootPath) + log.Printf("Dumping local repositories...%s", setting.RepoRootPath) zip.Verbose = false defer os.Remove("gogs-repo.zip") - if err := zip.PackTo(base.RepoRootPath, "gogs-repo.zip", true); err != nil { + if err := zip.PackTo(setting.RepoRootPath, "gogs-repo.zip", true); err != nil { log.Fatalf("Fail to dump local repositories: %v", err) } @@ -53,11 +53,11 @@ func runDump(*cli.Context) { log.Fatalf("Fail to create %s: %v", fileName, err) } - execDir, _ := base.ExecDir() - z.AddFile("gogs-repo.zip", path.Join(execDir, "gogs-repo.zip")) - z.AddFile("gogs-db.sql", path.Join(execDir, "gogs-db.sql")) - z.AddFile("custom/conf/app.ini", path.Join(execDir, "custom/conf/app.ini")) - z.AddDir("log", path.Join(execDir, "log")) + workDir, _ := setting.WorkDir() + z.AddFile("gogs-repo.zip", path.Join(workDir, "gogs-repo.zip")) + z.AddFile("gogs-db.sql", path.Join(workDir, "gogs-db.sql")) + z.AddFile("custom/conf/app.ini", path.Join(workDir, "custom/conf/app.ini")) + z.AddDir("log", path.Join(workDir, "log")) if err = z.Close(); err != nil { os.Remove(fileName) log.Fatalf("Fail to save %s: %v", fileName, err) diff --git a/cmd/fix.go b/cmd/fix.go index 809c00396f..3c2278ba90 100644 --- a/cmd/fix.go +++ b/cmd/fix.go @@ -10,7 +10,7 @@ import ( "github.com/codegangsta/cli" "github.com/gogits/gogs/models" - "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/modules/setting" ) var CmdFix = cli.Command{ @@ -22,14 +22,14 @@ var CmdFix = cli.Command{ } func runFix(k *cli.Context) { - execDir, _ := base.ExecDir() - newLogger(execDir) + workDir, _ := setting.WorkDir() + newLogger(workDir) - base.NewConfigContext() + setting.NewConfigContext() models.LoadModelsConfig() if models.UseSQLite3 { - os.Chdir(execDir) + os.Chdir(workDir) } models.SetEngine() diff --git a/cmd/serve.go b/cmd/serve.go index f7b0d2045d..47406dd009 100644 --- a/cmd/serve.go +++ b/cmd/serve.go @@ -16,7 +16,7 @@ import ( qlog "github.com/qiniu/log" "github.com/gogits/gogs/models" - "github.com/gogits/gogs/modules/base" + "github.com/gogits/gogs/modules/setting" ) var CmdServ = cli.Command{ @@ -41,14 +41,14 @@ func newLogger(logPath string) { } func setup(logPath string) { - execDir, _ := base.ExecDir() - newLogger(path.Join(execDir, logPath)) + workDir, _ := setting.WorkDir() + newLogger(path.Join(workDir, logPath)) - base.NewConfigContext() + setting.NewConfigContext() models.LoadModelsConfig() if models.UseSQLite3 { - os.Chdir(execDir) + os.Chdir(workDir) } models.SetEngine() @@ -182,7 +182,7 @@ func runServ(k *cli.Context) { models.SetRepoEnvs(user.Id, user.Name, repoName, repoUserName) gitcmd := exec.Command(verb, repoPath) - gitcmd.Dir = base.RepoRootPath + gitcmd.Dir = setting.RepoRootPath gitcmd.Stdout = os.Stdout gitcmd.Stdin = os.Stdin gitcmd.Stderr = os.Stderr diff --git a/cmd/web.go b/cmd/web.go index 0e8fc09b9e..2019b4405d 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -9,10 +9,10 @@ import ( "html/template" "net/http" "os" + "path" "github.com/codegangsta/cli" "github.com/go-martini/martini" - qlog "github.com/qiniu/log" "github.com/gogits/gogs/modules/auth" "github.com/gogits/gogs/modules/auth/apiv1" @@ -21,6 +21,7 @@ import ( "github.com/gogits/gogs/modules/log" "github.com/gogits/gogs/modules/middleware" "github.com/gogits/gogs/modules/middleware/binding" + "github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/routers" "github.com/gogits/gogs/routers/admin" "github.com/gogits/gogs/routers/api/v1" @@ -43,7 +44,8 @@ func newMartini() *martini.ClassicMartini { m := martini.New() m.Use(middleware.Logger()) m.Use(martini.Recovery()) - m.Use(martini.Static("public", martini.StaticOptions{SkipLogging: !base.DisableRouterLog})) + m.Use(martini.Static(path.Join(setting.StaticRootPath, "public"), + martini.StaticOptions{SkipLogging: !setting.DisableRouterLog})) m.MapTo(r, (*martini.Routes)(nil)) m.Action(r.Handle) return &martini.ClassicMartini{m, r} @@ -56,13 +58,14 @@ func runWeb(*cli.Context) { // Middlewares. m.Use(middleware.Renderer(middleware.RenderOptions{ + Directory: path.Join(setting.StaticRootPath, "templates"), Funcs: []template.FuncMap{base.TemplateFuncs}, IndentJSON: true, })) m.Use(middleware.InitContext()) reqSignIn := middleware.Toggle(&middleware.ToggleOptions{SignInRequire: true}) - ignSignIn := middleware.Toggle(&middleware.ToggleOptions{SignInRequire: base.Service.RequireSignInView}) + ignSignIn := middleware.Toggle(&middleware.ToggleOptions{SignInRequire: setting.Service.RequireSignInView}) ignSignInAndCsrf := middleware.Toggle(&middleware.ToggleOptions{DisableCsrf: true}) reqSignOut := middleware.Toggle(&middleware.ToggleOptions{SignOutRequire: true}) @@ -241,22 +244,19 @@ func runWeb(*cli.Context) { // Not found handler. m.NotFound(routers.NotFound) - protocol := base.Cfg.MustValue("server", "PROTOCOL", "http") - listenAddr := fmt.Sprintf("%s:%s", - base.Cfg.MustValue("server", "HTTP_ADDR", "0.0.0.0"), - base.Cfg.MustValue("server", "HTTP_PORT", "3000")) - - if protocol == "http" { - log.Info("Listen: http://%s", listenAddr) - if err := http.ListenAndServe(listenAddr, m); err != nil { - qlog.Error(err.Error()) - } - } else if protocol == "https" { - log.Info("Listen: https://%s", listenAddr) - if err := http.ListenAndServeTLS(listenAddr, base.Cfg.MustValue("server", "CERT_FILE"), - base.Cfg.MustValue("server", "KEY_FILE"), m); err != nil { - qlog.Error(err.Error()) - } + var err error + listenAddr := fmt.Sprintf("%s:%s", setting.HttpAddr, setting.HttpPort) + log.Info("Listen: %v://%s", setting.Protocol, listenAddr) + switch setting.Protocol { + case setting.HTTP: + err = http.ListenAndServe(listenAddr, m) + case setting.HTTPS: + err = http.ListenAndServeTLS(listenAddr, setting.CertFile, setting.KeyFile, m) + default: + log.Fatal("Invalid protocol: %s", setting.Protocol) + } + + if err != nil { + log.Fatal("Fail to start server: %v", err) } - qlog.Fatalf("Invalid protocol: %s", protocol) } |