Fixed #209
This commit is contained in:
parent
87854c95a9
commit
688ec6ecbd
37 changed files with 693 additions and 482 deletions
18
cmd/dump.go
18
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)
|
||||
|
|
10
cmd/fix.go
10
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()
|
||||
|
|
12
cmd/serve.go
12
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
|
||||
|
|
40
cmd/web.go
40
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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue