Skip to content

Commit 2eaefca

Browse files
tboergerThomas Boerger
authored andcommitted
Integrated new bindata and dropped superfluous version checks
1 parent de9a7cb commit 2eaefca

File tree

4 files changed

+37
-61
lines changed

4 files changed

+37
-61
lines changed

cmd/web.go

Lines changed: 24 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package cmd
77
import (
88
"crypto/tls"
99
"fmt"
10-
"io/ioutil"
1110
"net"
1211
"net/http"
1312
"net/http/fcgi"
@@ -30,6 +29,7 @@ import (
3029
"code.gitea.io/gitea/routers/org"
3130
"code.gitea.io/gitea/routers/repo"
3231
"code.gitea.io/gitea/routers/user"
32+
"github.com/go-macaron/bindata"
3333
"github.com/go-macaron/binding"
3434
"github.com/go-macaron/cache"
3535
"github.com/go-macaron/captcha"
@@ -73,45 +73,6 @@ type VerChecker struct {
7373
Expected string
7474
}
7575

76-
// checkVersion checks if binary matches the version of templates files.
77-
func checkVersion() {
78-
// Templates.
79-
data, err := ioutil.ReadFile(setting.StaticRootPath + "/templates/.VERSION")
80-
if err != nil {
81-
log.Fatal(4, "Fail to read 'templates/.VERSION': %v", err)
82-
}
83-
tplVer := string(data)
84-
if tplVer != setting.AppVer {
85-
if version.Compare(tplVer, setting.AppVer, ">") {
86-
log.Fatal(4, "Binary version is lower than template file version, did you forget to recompile Gogs?")
87-
} else {
88-
log.Fatal(4, "Binary version is higher than template file version, did you forget to update template files?")
89-
}
90-
}
91-
92-
// Check dependency version.
93-
checkers := []VerChecker{
94-
{"github.com/go-xorm/xorm", func() string { return xorm.Version }, "0.5.5"},
95-
{"github.com/go-macaron/binding", binding.Version, "0.3.2"},
96-
{"github.com/go-macaron/cache", cache.Version, "0.1.2"},
97-
{"github.com/go-macaron/csrf", csrf.Version, "0.1.0"},
98-
{"github.com/go-macaron/i18n", i18n.Version, "0.3.0"},
99-
{"github.com/go-macaron/session", session.Version, "0.1.6"},
100-
{"github.com/go-macaron/toolbox", toolbox.Version, "0.1.0"},
101-
{"gopkg.in/ini.v1", ini.Version, "1.8.4"},
102-
{"gopkg.in/macaron.v1", macaron.Version, "1.1.7"},
103-
{"code.gitea.io/git", git.Version, "0.4.1"},
104-
}
105-
for _, c := range checkers {
106-
if !version.Compare(c.Version(), c.Expected, ">=") {
107-
log.Fatal(4, `Dependency outdated!
108-
Package '%s' current version (%s) is below requirement (%s),
109-
please use following command to update this package and recompile Gogs:
110-
go get -u %[1]s`, c.ImportPath, c.Version(), c.Expected)
111-
}
112-
}
113-
}
114-
11576
// newMacaron initializes Macaron instance.
11677
func newMacaron() *macaron.Macaron {
11778
m := macaron.New()
@@ -126,9 +87,16 @@ func newMacaron() *macaron.Macaron {
12687
m.SetURLPrefix(setting.AppSubURL)
12788
}
12889
m.Use(macaron.Static(
129-
path.Join(setting.StaticRootPath, "public"),
90+
"public",
13091
macaron.StaticOptions{
13192
SkipLogging: setting.DisableRouterLog,
93+
FileSystem: bindata.Static(bindata.Options{
94+
Asset: public.Asset,
95+
AssetDir: public.AssetDir,
96+
AssetInfo: public.AssetInfo,
97+
AssetNames: public.AssetNames,
98+
Prefix: "",
99+
}),
132100
},
133101
))
134102
m.Use(macaron.Static(
@@ -139,23 +107,31 @@ func newMacaron() *macaron.Macaron {
139107
},
140108
))
141109

110+
templateOptions := bindata.Options{
111+
Asset: templates.Asset,
112+
AssetDir: templates.AssetDir,
113+
AssetInfo: templates.AssetInfo,
114+
AssetNames: templates.AssetNames,
115+
Prefix: "",
116+
}
117+
142118
funcMap := template.NewFuncMap()
143119
m.Use(macaron.Renderer(macaron.RenderOptions{
144-
Directory: path.Join(setting.StaticRootPath, "templates"),
145-
AppendDirectories: []string{path.Join(setting.CustomPath, "templates")},
146-
Funcs: funcMap,
147-
IndentJSON: macaron.Env != macaron.PROD,
120+
AppendDirectories: []string{path.Join(setting.CustomPath, "templates")},
121+
Funcs: funcMap,
122+
IndentJSON: macaron.Env != macaron.PROD,
123+
TemplateFileSystem: bindata.Templates(templateOptions),
148124
}))
149-
models.InitMailRender(path.Join(setting.StaticRootPath, "templates/mail"),
125+
models.InitMailRender(templateOptions,
150126
path.Join(setting.CustomPath, "templates/mail"), funcMap)
151127

152-
localeNames, err := bindata.AssetDir("conf/locale")
128+
localeNames, err := conf.AssetDir("locale")
153129
if err != nil {
154130
log.Fatal(4, "Fail to list locale files: %v", err)
155131
}
156132
localFiles := make(map[string][]byte)
157133
for _, name := range localeNames {
158-
localFiles[name] = bindata.MustAsset("conf/locale/" + name)
134+
localFiles[name] = conf.MustAsset("locale/" + name)
159135
}
160136
m.Use(i18n.I18n(i18n.Options{
161137
SubURL: setting.AppSubURL,
@@ -199,7 +175,6 @@ func runWeb(ctx *cli.Context) error {
199175
setting.CustomConf = ctx.String("config")
200176
}
201177
routers.GlobalInit()
202-
checkVersion()
203178

204179
m := newMacaron()
205180

models/mail.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"html/template"
1010
"path"
1111

12+
"github.com/go-macaron/bindata"
1213
"gopkg.in/gomail.v2"
1314
"gopkg.in/macaron.v1"
1415

@@ -38,12 +39,12 @@ type mailRenderInterface interface {
3839
var mailRender mailRenderInterface
3940

4041
// InitMailRender initializes the macaron mail renderer
41-
func InitMailRender(dir, appendDir string, funcMap []template.FuncMap) {
42+
func InitMailRender(templateOptions bindata.Options, appendDir string, funcMap []template.FuncMap) {
4243
opt := &macaron.RenderOptions{
43-
Directory: dir,
44-
AppendDirectories: []string{appendDir},
45-
Funcs: funcMap,
46-
Extensions: []string{".tmpl", ".html"},
44+
TemplateFileSystem: bindata.Templates(templateOptions),
45+
AppendDirectories: []string{appendDir},
46+
Funcs: funcMap,
47+
Extensions: []string{".tmpl", ".html"},
4748
}
4849
ts := macaron.NewTemplateSet()
4950
ts.Set(macaron.DEFAULT_TPL_SET_NAME, opt)

models/repo.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"time"
2121

2222
"code.gitea.io/git"
23-
"code.gitea.io/gitea/modules/bindata"
23+
"code.gitea.io/gitea/conf"
2424
"code.gitea.io/gitea/modules/log"
2525
"code.gitea.io/gitea/modules/markdown"
2626
"code.gitea.io/gitea/modules/process"
@@ -60,7 +60,7 @@ func LoadRepoConfig() {
6060
types := []string{"gitignore", "license", "readme", "label"}
6161
typeFiles := make([][]string, 4)
6262
for i, t := range types {
63-
files, err := bindata.AssetDir("conf/" + t)
63+
files, err := conf.AssetDir(t)
6464
if err != nil {
6565
log.Fatal(4, "Fail to get %s files: %v", t, err)
6666
}
@@ -771,14 +771,14 @@ type CreateRepoOptions struct {
771771
}
772772

773773
func getRepoInitFile(tp, name string) ([]byte, error) {
774-
relPath := path.Join("conf", tp, strings.TrimLeft(name, "./"))
774+
relPath := path.Join(tp, strings.TrimLeft(name, "./"))
775775

776776
// Use custom file when available.
777-
customPath := path.Join(setting.CustomPath, relPath)
777+
customPath := path.Join(setting.CustomPath, "conf", relPath)
778778
if com.IsFile(customPath) {
779779
return ioutil.ReadFile(customPath)
780780
}
781-
return bindata.Asset(relPath)
781+
return conf.Asset(relPath)
782782
}
783783

784784
func prepareRepoCommit(repo *Repository, tmpDir, repoPath string, opts CreateRepoOptions) error {

modules/setting/setting.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"gopkg.in/ini.v1"
2626
"strk.kbt.io/projects/go/libravatar"
2727

28-
"code.gitea.io/gitea/modules/bindata"
28+
"code.gitea.io/gitea/conf"
2929
"code.gitea.io/gitea/modules/log"
3030
"code.gitea.io/gitea/modules/user"
3131
)
@@ -352,7 +352,7 @@ func NewContext() {
352352
log.Fatal(4, "Fail to get work directory: %v", err)
353353
}
354354

355-
Cfg, err = ini.Load(bindata.MustAsset("conf/app.ini"))
355+
Cfg, err = ini.Load(conf.MustAsset("app.ini"))
356356
if err != nil {
357357
log.Fatal(4, "Fail to parse 'conf/app.ini': %v", err)
358358
}

0 commit comments

Comments
 (0)