|
@@ -8,7 +8,6 @@ import (
|
|
"crypto/tls"
|
|
"crypto/tls"
|
|
"fmt"
|
|
"fmt"
|
|
"io"
|
|
"io"
|
|
- "io/ioutil"
|
|
|
|
"net"
|
|
"net"
|
|
"net/http"
|
|
"net/http"
|
|
"net/http/fcgi"
|
|
"net/http/fcgi"
|
|
@@ -24,19 +23,19 @@ import (
|
|
"github.com/go-macaron/i18n"
|
|
"github.com/go-macaron/i18n"
|
|
"github.com/go-macaron/session"
|
|
"github.com/go-macaron/session"
|
|
"github.com/go-macaron/toolbox"
|
|
"github.com/go-macaron/toolbox"
|
|
- "github.com/mcuadros/go-version"
|
|
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
"github.com/unknwon/com"
|
|
"github.com/unknwon/com"
|
|
"github.com/urfave/cli"
|
|
"github.com/urfave/cli"
|
|
log "gopkg.in/clog.v1"
|
|
log "gopkg.in/clog.v1"
|
|
"gopkg.in/macaron.v1"
|
|
"gopkg.in/macaron.v1"
|
|
|
|
|
|
- "github.com/G-Node/gogs/internal/bindata"
|
|
|
|
|
|
+ "github.com/G-Node/gogs/internal/assets/conf"
|
|
|
|
+ "github.com/G-Node/gogs/internal/assets/public"
|
|
|
|
+ "github.com/G-Node/gogs/internal/assets/templates"
|
|
"github.com/G-Node/gogs/internal/context"
|
|
"github.com/G-Node/gogs/internal/context"
|
|
"github.com/G-Node/gogs/internal/dav"
|
|
"github.com/G-Node/gogs/internal/dav"
|
|
"github.com/G-Node/gogs/internal/db"
|
|
"github.com/G-Node/gogs/internal/db"
|
|
"github.com/G-Node/gogs/internal/form"
|
|
"github.com/G-Node/gogs/internal/form"
|
|
- "github.com/G-Node/gogs/internal/mailer"
|
|
|
|
"github.com/G-Node/gogs/internal/route"
|
|
"github.com/G-Node/gogs/internal/route"
|
|
"github.com/G-Node/gogs/internal/route/admin"
|
|
"github.com/G-Node/gogs/internal/route/admin"
|
|
apiv1 "github.com/G-Node/gogs/internal/route/api/v1"
|
|
apiv1 "github.com/G-Node/gogs/internal/route/api/v1"
|
|
@@ -61,23 +60,6 @@ and it takes care of all the other things for you`,
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
|
|
-// checkVersion checks if binary matches the version of templates files.
|
|
|
|
-func checkVersion() {
|
|
|
|
- // Templates.
|
|
|
|
- data, err := ioutil.ReadFile(setting.StaticRootPath + "/templates/.VERSION")
|
|
|
|
- if err != nil {
|
|
|
|
- log.Fatal(2, "Fail to read 'templates/.VERSION': %v", err)
|
|
|
|
- }
|
|
|
|
- tplVer := strings.TrimSpace(string(data))
|
|
|
|
- if tplVer != setting.AppVer {
|
|
|
|
- if version.Compare(tplVer, setting.AppVer, ">") {
|
|
|
|
- log.Fatal(2, "Binary version is lower than template file version, did you forget to recompile Gogs?")
|
|
|
|
- } else {
|
|
|
|
- log.Fatal(2, "Binary version is higher than template file version, did you forget to update template files?")
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
// newMacaron initializes Macaron instance.
|
|
// newMacaron initializes Macaron instance.
|
|
func newMacaron() *macaron.Macaron {
|
|
func newMacaron() *macaron.Macaron {
|
|
m := macaron.New()
|
|
m := macaron.New()
|
|
@@ -91,12 +73,26 @@ func newMacaron() *macaron.Macaron {
|
|
if setting.Protocol == setting.SCHEME_FCGI {
|
|
if setting.Protocol == setting.SCHEME_FCGI {
|
|
m.SetURLPrefix(setting.AppSubURL)
|
|
m.SetURLPrefix(setting.AppSubURL)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // Register custom middleware first to make it possible to override files under "public".
|
|
|
|
+ m.Use(macaron.Static(
|
|
|
|
+ path.Join(setting.CustomPath, "public"),
|
|
|
|
+ macaron.StaticOptions{
|
|
|
|
+ SkipLogging: setting.DisableRouterLog,
|
|
|
|
+ },
|
|
|
|
+ ))
|
|
|
|
+ var publicFs http.FileSystem
|
|
|
|
+ if !setting.LoadAssetsFromDisk {
|
|
|
|
+ publicFs = public.NewFileSystem()
|
|
|
|
+ }
|
|
m.Use(macaron.Static(
|
|
m.Use(macaron.Static(
|
|
path.Join(setting.StaticRootPath, "public"),
|
|
path.Join(setting.StaticRootPath, "public"),
|
|
macaron.StaticOptions{
|
|
macaron.StaticOptions{
|
|
SkipLogging: setting.DisableRouterLog,
|
|
SkipLogging: setting.DisableRouterLog,
|
|
|
|
+ FileSystem: publicFs,
|
|
},
|
|
},
|
|
))
|
|
))
|
|
|
|
+
|
|
m.Use(macaron.Static(
|
|
m.Use(macaron.Static(
|
|
setting.AvatarUploadPath,
|
|
setting.AvatarUploadPath,
|
|
macaron.StaticOptions{
|
|
macaron.StaticOptions{
|
|
@@ -112,23 +108,24 @@ func newMacaron() *macaron.Macaron {
|
|
},
|
|
},
|
|
))
|
|
))
|
|
|
|
|
|
- funcMap := template.NewFuncMap()
|
|
|
|
- m.Use(macaron.Renderer(macaron.RenderOptions{
|
|
|
|
|
|
+ renderOpt := macaron.RenderOptions{
|
|
Directory: path.Join(setting.StaticRootPath, "templates"),
|
|
Directory: path.Join(setting.StaticRootPath, "templates"),
|
|
AppendDirectories: []string{path.Join(setting.CustomPath, "templates")},
|
|
AppendDirectories: []string{path.Join(setting.CustomPath, "templates")},
|
|
- Funcs: funcMap,
|
|
|
|
|
|
+ Funcs: template.FuncMap(),
|
|
IndentJSON: macaron.Env != macaron.PROD,
|
|
IndentJSON: macaron.Env != macaron.PROD,
|
|
- }))
|
|
|
|
- mailer.InitMailRender(path.Join(setting.StaticRootPath, "templates/mail"),
|
|
|
|
- path.Join(setting.CustomPath, "templates/mail"), funcMap)
|
|
|
|
|
|
+ }
|
|
|
|
+ if !setting.LoadAssetsFromDisk {
|
|
|
|
+ renderOpt.TemplateFileSystem = templates.NewTemplateFileSystem("", renderOpt.AppendDirectories[0])
|
|
|
|
+ }
|
|
|
|
+ m.Use(macaron.Renderer(renderOpt))
|
|
|
|
|
|
- localeNames, err := bindata.AssetDir("conf/locale")
|
|
|
|
|
|
+ localeNames, err := conf.AssetDir("conf/locale")
|
|
if err != nil {
|
|
if err != nil {
|
|
log.Fatal(4, "Fail to list locale files: %v", err)
|
|
log.Fatal(4, "Fail to list locale files: %v", err)
|
|
}
|
|
}
|
|
localFiles := make(map[string][]byte)
|
|
localFiles := make(map[string][]byte)
|
|
for _, name := range localeNames {
|
|
for _, name := range localeNames {
|
|
- localFiles[name] = bindata.MustAsset("conf/locale/" + name)
|
|
|
|
|
|
+ localFiles[name] = conf.MustAsset("conf/locale/" + name)
|
|
}
|
|
}
|
|
m.Use(i18n.I18n(i18n.Options{
|
|
m.Use(i18n.I18n(i18n.Options{
|
|
SubURL: setting.AppSubURL,
|
|
SubURL: setting.AppSubURL,
|
|
@@ -176,7 +173,6 @@ func runWeb(c *cli.Context) error {
|
|
setting.CustomConf = c.String("config")
|
|
setting.CustomConf = c.String("config")
|
|
}
|
|
}
|
|
route.GlobalInit()
|
|
route.GlobalInit()
|
|
- checkVersion()
|
|
|
|
|
|
|
|
m := newMacaron()
|
|
m := newMacaron()
|
|
|
|
|
|
@@ -570,7 +566,7 @@ func runWeb(c *cli.Context) error {
|
|
m.Combo("/compare/*", repo.MustAllowPulls).Get(repo.CompareAndPullRequest).
|
|
m.Combo("/compare/*", repo.MustAllowPulls).Get(repo.CompareAndPullRequest).
|
|
Post(bindIgnErr(form.NewIssue{}), repo.CompareAndPullRequestPost)
|
|
Post(bindIgnErr(form.NewIssue{}), repo.CompareAndPullRequestPost)
|
|
|
|
|
|
- if _, err := bindata.Asset("conf/datacite/datacite.yml"); err != nil {
|
|
|
|
|
|
+ if _, err := conf.Asset("conf/datacite/datacite.yml"); err != nil {
|
|
log.Fatal(2, "%v", err)
|
|
log.Fatal(2, "%v", err)
|
|
}
|
|
}
|
|
m.Group("", func() {
|
|
m.Group("", func() {
|
|
@@ -720,7 +716,7 @@ func runWeb(c *cli.Context) error {
|
|
} else {
|
|
} else {
|
|
listenAddr = fmt.Sprintf("%s:%s", setting.HTTPAddr, setting.HTTPPort)
|
|
listenAddr = fmt.Sprintf("%s:%s", setting.HTTPAddr, setting.HTTPPort)
|
|
}
|
|
}
|
|
- log.Info("Listen: %v://%s%s", setting.Protocol, listenAddr, setting.AppSubURL)
|
|
|
|
|
|
+ log.Info("Listen on %v://%s%s", setting.Protocol, listenAddr, setting.AppSubURL)
|
|
|
|
|
|
var err error
|
|
var err error
|
|
switch setting.Protocol {
|
|
switch setting.Protocol {
|