Skip to content

Commit ac2177b

Browse files
committed
Integrated new bindata and dropped superfluous version checks
1 parent 2b81483 commit ac2177b

File tree

4 files changed

+40
-69
lines changed

4 files changed

+40
-69
lines changed

cmd/web.go

Lines changed: 27 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ package cmd
77
import (
88
"crypto/tls"
99
"fmt"
10-
"io/ioutil"
1110
"net"
1211
"net/http"
1312
"net/http/fcgi"
1413
"os"
1514
"path"
1615
"strings"
1716

17+
"github.com/go-macaron/bindata"
1818
"github.com/go-macaron/binding"
1919
"github.com/go-macaron/cache"
2020
"github.com/go-macaron/captcha"
@@ -23,29 +23,25 @@ import (
2323
"github.com/go-macaron/i18n"
2424
"github.com/go-macaron/session"
2525
"github.com/go-macaron/toolbox"
26-
"github.com/go-xorm/xorm"
27-
"github.com/mcuadros/go-version"
2826
"github.com/urfave/cli"
29-
"gopkg.in/ini.v1"
3027
"gopkg.in/macaron.v1"
3128

32-
"github.com/gogits/git-module"
33-
"github.com/gogits/go-gogs-client"
34-
29+
"github.com/go-gitea/gitea/conf"
3530
"github.com/go-gitea/gitea/models"
3631
"github.com/go-gitea/gitea/modules/auth"
37-
"github.com/go-gitea/gitea/modules/bindata"
3832
"github.com/go-gitea/gitea/modules/context"
3933
"github.com/go-gitea/gitea/modules/log"
4034
"github.com/go-gitea/gitea/modules/setting"
4135
"github.com/go-gitea/gitea/modules/template"
36+
"github.com/go-gitea/gitea/public"
4237
"github.com/go-gitea/gitea/routers"
4338
"github.com/go-gitea/gitea/routers/admin"
4439
apiv1 "github.com/go-gitea/gitea/routers/api/v1"
4540
"github.com/go-gitea/gitea/routers/dev"
4641
"github.com/go-gitea/gitea/routers/org"
4742
"github.com/go-gitea/gitea/routers/repo"
4843
"github.com/go-gitea/gitea/routers/user"
44+
"github.com/go-gitea/gitea/templates"
4945
)
5046

5147
// CmdWeb represents the available web sub-command.
@@ -68,46 +64,6 @@ type VerChecker struct {
6864
Expected string
6965
}
7066

71-
// checkVersion checks if binary matches the version of templates files.
72-
func checkVersion() {
73-
// Templates.
74-
data, err := ioutil.ReadFile(setting.StaticRootPath + "/templates/.VERSION")
75-
if err != nil {
76-
log.Fatal(4, "Fail to read 'templates/.VERSION': %v", err)
77-
}
78-
tplVer := string(data)
79-
if tplVer != setting.AppVer {
80-
if version.Compare(tplVer, setting.AppVer, ">") {
81-
log.Fatal(4, "Binary version is lower than template file version, did you forget to recompile Gogs?")
82-
} else {
83-
log.Fatal(4, "Binary version is higher than template file version, did you forget to update template files?")
84-
}
85-
}
86-
87-
// Check dependency version.
88-
checkers := []VerChecker{
89-
{"github.com/go-xorm/xorm", func() string { return xorm.Version }, "0.5.5"},
90-
{"github.com/go-macaron/binding", binding.Version, "0.3.2"},
91-
{"github.com/go-macaron/cache", cache.Version, "0.1.2"},
92-
{"github.com/go-macaron/csrf", csrf.Version, "0.1.0"},
93-
{"github.com/go-macaron/i18n", i18n.Version, "0.3.0"},
94-
{"github.com/go-macaron/session", session.Version, "0.1.6"},
95-
{"github.com/go-macaron/toolbox", toolbox.Version, "0.1.0"},
96-
{"gopkg.in/ini.v1", ini.Version, "1.8.4"},
97-
{"gopkg.in/macaron.v1", macaron.Version, "1.1.7"},
98-
{"github.com/gogits/git-module", git.Version, "0.4.1"},
99-
{"github.com/gogits/go-gogs-client", gogs.Version, "0.12.1"},
100-
}
101-
for _, c := range checkers {
102-
if !version.Compare(c.Version(), c.Expected, ">=") {
103-
log.Fatal(4, `Dependency outdated!
104-
Package '%s' current version (%s) is below requirement (%s),
105-
please use following command to update this package and recompile Gogs:
106-
go get -u %[1]s`, c.ImportPath, c.Version(), c.Expected)
107-
}
108-
}
109-
}
110-
11167
// newMacaron initializes Macaron instance.
11268
func newMacaron() *macaron.Macaron {
11369
m := macaron.New()
@@ -122,9 +78,16 @@ func newMacaron() *macaron.Macaron {
12278
m.SetURLPrefix(setting.AppSubUrl)
12379
}
12480
m.Use(macaron.Static(
125-
path.Join(setting.StaticRootPath, "public"),
81+
"public",
12682
macaron.StaticOptions{
12783
SkipLogging: setting.DisableRouterLog,
84+
FileSystem: bindata.Static(bindata.Options{
85+
Asset: public.Asset,
86+
AssetDir: public.AssetDir,
87+
AssetInfo: public.AssetInfo,
88+
AssetNames: public.AssetNames,
89+
Prefix: "",
90+
}),
12891
},
12992
))
13093
m.Use(macaron.Static(
@@ -135,23 +98,31 @@ func newMacaron() *macaron.Macaron {
13598
},
13699
))
137100

101+
templateOptions := bindata.Options{
102+
Asset: templates.Asset,
103+
AssetDir: templates.AssetDir,
104+
AssetInfo: templates.AssetInfo,
105+
AssetNames: templates.AssetNames,
106+
Prefix: "",
107+
}
108+
138109
funcMap := template.NewFuncMap()
139110
m.Use(macaron.Renderer(macaron.RenderOptions{
140-
Directory: path.Join(setting.StaticRootPath, "templates"),
141-
AppendDirectories: []string{path.Join(setting.CustomPath, "templates")},
142-
Funcs: funcMap,
143-
IndentJSON: macaron.Env != macaron.PROD,
111+
AppendDirectories: []string{path.Join(setting.CustomPath, "templates")},
112+
Funcs: funcMap,
113+
IndentJSON: macaron.Env != macaron.PROD,
114+
TemplateFileSystem: bindata.Templates(templateOptions),
144115
}))
145-
models.InitMailRender(path.Join(setting.StaticRootPath, "templates/mail"),
116+
models.InitMailRender(templateOptions,
146117
path.Join(setting.CustomPath, "templates/mail"), funcMap)
147118

148-
localeNames, err := bindata.AssetDir("conf/locale")
119+
localeNames, err := conf.AssetDir("locale")
149120
if err != nil {
150121
log.Fatal(4, "Fail to list locale files: %v", err)
151122
}
152123
localFiles := make(map[string][]byte)
153124
for _, name := range localeNames {
154-
localFiles[name] = bindata.MustAsset("conf/locale/" + name)
125+
localFiles[name] = conf.MustAsset("locale/" + name)
155126
}
156127
m.Use(i18n.I18n(i18n.Options{
157128
SubURL: setting.AppSubUrl,
@@ -195,7 +166,6 @@ func runWeb(ctx *cli.Context) error {
195166
setting.CustomConf = ctx.String("config")
196167
}
197168
routers.GlobalInit()
198-
checkVersion()
199169

200170
m := newMacaron()
201171

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

@@ -37,12 +38,12 @@ type MailRender interface {
3738

3839
var mailRender MailRender
3940

40-
func InitMailRender(dir, appendDir string, funcMap []template.FuncMap) {
41+
func InitMailRender(templateOptions bindata.Options, appendDir string, funcMap []template.FuncMap) {
4142
opt := &macaron.RenderOptions{
42-
Directory: dir,
43-
AppendDirectories: []string{appendDir},
44-
Funcs: funcMap,
45-
Extensions: []string{".tmpl", ".html"},
43+
TemplateFileSystem: bindata.Templates(templateOptions),
44+
AppendDirectories: []string{appendDir},
45+
Funcs: funcMap,
46+
Extensions: []string{".tmpl", ".html"},
4647
}
4748
ts := macaron.NewTemplateSet()
4849
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
@@ -28,7 +28,7 @@ import (
2828
git "github.com/gogits/git-module"
2929
api "github.com/gogits/go-gogs-client"
3030

31-
"github.com/go-gitea/gitea/modules/bindata"
31+
"github.com/go-gitea/gitea/conf"
3232
"github.com/go-gitea/gitea/modules/log"
3333
"github.com/go-gitea/gitea/modules/markdown"
3434
"github.com/go-gitea/gitea/modules/process"
@@ -62,7 +62,7 @@ func LoadRepoConfig() {
6262
types := []string{"gitignore", "license", "readme", "label"}
6363
typeFiles := make([][]string, 4)
6464
for i, t := range types {
65-
files, err := bindata.AssetDir("conf/" + t)
65+
files, err := conf.AssetDir(t)
6666
if err != nil {
6767
log.Fatal(4, "Fail to get %s files: %v", t, err)
6868
}
@@ -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-
"github.com/go-gitea/gitea/modules/bindata"
28+
"github.com/go-gitea/gitea/conf"
2929
"github.com/go-gitea/gitea/modules/log"
3030
"github.com/go-gitea/gitea/modules/user"
3131
)
@@ -335,7 +335,7 @@ func NewContext() {
335335
log.Fatal(4, "Fail to get work directory: %v", err)
336336
}
337337

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

0 commit comments

Comments
 (0)