Skip to content

Commit 852df02

Browse files
lunnyjeffliu27
authored andcommitted
Use vfsgen instead of go-bindata (go-gitea#7080)
* use vfsgen instead of go-bindata * fix templates * fix fmt * vendor vsfgen
1 parent 7bf74cf commit 852df02

36 files changed

+1224
-612
lines changed

Makefile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,7 @@ vet:
9797

9898
.PHONY: generate
9999
generate:
100-
@hash go-bindata > /dev/null 2>&1; if [ $$? -ne 0 ]; then \
101-
$(GO) get -u github.com/jteeuwen/go-bindata/go-bindata; \
102-
fi
103-
$(GO) generate $(PACKAGES)
100+
GO111MODULE=on $(GO) generate $(PACKAGES)
104101

105102
.PHONY: generate-swagger
106103
generate-swagger:

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ require (
3030
github.com/denisenkom/go-mssqldb v0.0.0-20181014144952-4e0d7dc8888f
3131
github.com/dgrijalva/jwt-go v0.0.0-20161101193935-9ed569b5d1ac
3232
github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712 // indirect
33-
github.com/elazarl/go-bindata-assetfs v0.0.0-20151224045452-57eb5e1fc594 // indirect
3433
github.com/emirpasic/gods v1.12.0
3534
github.com/etcd-io/bbolt v1.3.2 // indirect
3635
github.com/ethantkoenig/rupture v0.0.0-20180203182544-0a76f03a811a
@@ -44,7 +43,6 @@ require (
4443
github.com/facebookgo/subset v0.0.0-20150612182917-8dac2c3c4870 // indirect
4544
github.com/glycerine/go-unsnap-stream v0.0.0-20180323001048-9f0cb55181dd // indirect
4645
github.com/glycerine/goconvey v0.0.0-20190315024820-982ee783a72e // indirect
47-
github.com/go-macaron/bindata v0.0.0-20161222093048-85786f57eee3
4846
github.com/go-macaron/binding v0.0.0-20160711225916-9440f336b443
4947
github.com/go-macaron/cache v0.0.0-20151013081102-561735312776
5048
github.com/go-macaron/captcha v0.0.0-20151123225153-8aa5919789ab
@@ -103,7 +101,9 @@ require (
103101
github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca // indirect
104102
github.com/satori/go.uuid v1.2.0
105103
github.com/sergi/go-diff v1.0.0
104+
github.com/shurcooL/httpfs v0.0.0-20190527155220-6a4d4a70508b // indirect
106105
github.com/shurcooL/sanitized_anchor_name v0.0.0-20160918041101-1dba4b3954bc // indirect
106+
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd
107107
github.com/siddontang/go-snappy v0.0.0-20140704025258-d8f7bb82a96d // indirect
108108
github.com/smartystreets/goconvey v0.0.0-20190306220146-200a235640ff // indirect
109109
github.com/steveyen/gtreap v0.0.0-20150807155958-0abe01ef9be2 // indirect

go.sum

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ github.com/dgrijalva/jwt-go v0.0.0-20161101193935-9ed569b5d1ac h1:xrQJVwQCGqDvOO
6262
github.com/dgrijalva/jwt-go v0.0.0-20161101193935-9ed569b5d1ac/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
6363
github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712 h1:aaQcKT9WumO6JEJcRyTqFVq4XUZiUcKR2/GI31TOcz8=
6464
github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
65-
github.com/elazarl/go-bindata-assetfs v0.0.0-20151224045452-57eb5e1fc594 h1:McZ/pt/pP/XAbLMDQGzm/iQUwW6OXmKVbFtmH9klWmc=
66-
github.com/elazarl/go-bindata-assetfs v0.0.0-20151224045452-57eb5e1fc594/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
6765
github.com/emirpasic/gods v1.9.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
6866
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
6967
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
@@ -97,8 +95,6 @@ github.com/glycerine/go-unsnap-stream v0.0.0-20180323001048-9f0cb55181dd h1:r04M
9795
github.com/glycerine/go-unsnap-stream v0.0.0-20180323001048-9f0cb55181dd/go.mod h1:/20jfyN9Y5QPEAprSgKAUr+glWDY39ZiUEAYOEv5dsE=
9896
github.com/glycerine/goconvey v0.0.0-20190315024820-982ee783a72e h1:SiEs4J3BKVIeaWrH3tKaz3QLZhJ68iJ/A4xrzIoE5+Y=
9997
github.com/glycerine/goconvey v0.0.0-20190315024820-982ee783a72e/go.mod h1:Ogl1Tioa0aV7gstGFO7KhffUsb9M4ydbEbbxpcEDc24=
100-
github.com/go-macaron/bindata v0.0.0-20161222093048-85786f57eee3 h1:n0H90987ZwasTc9r/RnuaU1G5ePfzLG6Bkc1cY3KqnY=
101-
github.com/go-macaron/bindata v0.0.0-20161222093048-85786f57eee3/go.mod h1:NkmXhFuAlCOqgV5EWhU1DKLrgztCEIVXGmr2DZv/+sk=
10298
github.com/go-macaron/binding v0.0.0-20160711225916-9440f336b443 h1:i801KPR7j76uRMLLlGVyb0hiYbgX1FM5+ur81TJWzIw=
10399
github.com/go-macaron/binding v0.0.0-20160711225916-9440f336b443/go.mod h1:u+H6rwW+HQwUL+w5uaEJSpIlVZDye1o9MB4Su0JfRfM=
104100
github.com/go-macaron/cache v0.0.0-20151013081102-561735312776 h1:UYIHS1r0WotqB5cIa0PAiV0m6GzD9rDBcn4alp5JgCw=
@@ -282,8 +278,12 @@ github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
282278
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
283279
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24 h1:pntxY8Ary0t43dCZ5dqY4YTJCObLY1kIXl0uzMv+7DE=
284280
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
281+
github.com/shurcooL/httpfs v0.0.0-20190527155220-6a4d4a70508b h1:4kg1wyftSKxLtnPAvcRWakIPpokB9w780/KwrNLnfPA=
282+
github.com/shurcooL/httpfs v0.0.0-20190527155220-6a4d4a70508b/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg=
285283
github.com/shurcooL/sanitized_anchor_name v0.0.0-20160918041101-1dba4b3954bc h1:3wIrJvFb3Pf6B/2mDBnN1G5IfUVev4X5apadQlWOczE=
286284
github.com/shurcooL/sanitized_anchor_name v0.0.0-20160918041101-1dba4b3954bc/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
285+
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd h1:ug7PpSOB5RBPK1Kg6qskGBoP3Vnj/aNYFTznWvlkGo0=
286+
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw=
287287
github.com/siddontang/go-snappy v0.0.0-20140704025258-d8f7bb82a96d h1:qQWKKOvHN7Q9c6GdmUteCef2F9ubxMpxY1IKwpIKz68=
288288
github.com/siddontang/go-snappy v0.0.0-20140704025258-d8f7bb82a96d/go.mod h1:vq0tzqLRu6TS7Id0wMo2N5QzJoKedVeovOpHjnykSzY=
289289
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
@@ -348,6 +348,7 @@ golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e h1:nFYrTHrdrAOpShe27kaFHjsqY
348348
golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
349349
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
350350
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
351+
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635 h1:2eB4G6bDQDeP69ZXbOKC00S2Kf6TIiRS+DzfKsKeQU0=
351352
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
352353
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
353354
google.golang.org/appengine v1.2.0 h1:S0iUepdCWODXRvtE+gcRDd15L+k+k1AiHlMiMjefH24=

main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import (
2121
_ "code.gitea.io/gitea/modules/markup/markdown"
2222
_ "code.gitea.io/gitea/modules/markup/orgmode"
2323

24+
// for embed
25+
_ "github.com/shurcooL/vfsgen"
26+
2427
"github.com/urfave/cli"
2528
)
2629

modules/options/main.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// +build ignore
2+
3+
package main
4+
5+
import (
6+
"log"
7+
"net/http"
8+
9+
"github.com/shurcooL/vfsgen"
10+
)
11+
12+
func main() {
13+
var fsTemplates http.FileSystem = http.Dir("../../options")
14+
err := vfsgen.Generate(fsTemplates, vfsgen.Options{
15+
PackageName: "options",
16+
BuildTags: "bindata",
17+
VariableName: "Assets",
18+
Filename: "bindata.go",
19+
})
20+
if err != nil {
21+
log.Fatal("%v", err)
22+
}
23+
}

modules/options/options.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@
44

55
package options
66

7-
//go:generate go-bindata -tags "bindata" -ignore "TRANSLATORS" -pkg "options" -o "bindata.go" ../../options/...
7+
//go:generate go run -mod=vendor main.go
88
//go:generate go fmt bindata.go
9-
//go:generate sed -i.bak s/..\/..\/options\/// bindata.go
10-
//go:generate rm -f bindata.go.bak
119

1210
type directorySet map[string][]string
1311

modules/options/static.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func Dir(name string) ([]string, error) {
4141
result = append(result, files...)
4242
}
4343

44-
files, err := AssetDir(path.Join("..", "..", "options", name))
44+
files, err := AssetDir(name)
4545

4646
if err != nil {
4747
return []string{}, fmt.Errorf("Failed to read embedded directory. %v", err)
@@ -52,6 +52,24 @@ func Dir(name string) ([]string, error) {
5252
return directories.AddAndGet(name, result), nil
5353
}
5454

55+
func AssetDir(dirName string) ([]string, error) {
56+
d, err := Assets.Open(dirName)
57+
if err != nil {
58+
return nil, err
59+
}
60+
defer d.Close()
61+
62+
files, err := d.Readdir(-1)
63+
if err != nil {
64+
return nil, err
65+
}
66+
var results = make([]string, 0, len(files))
67+
for _, file := range files {
68+
results = append(results, file.Name())
69+
}
70+
return results, nil
71+
}
72+
5573
// Locale reads the content of a specific locale from bindata or custom path.
5674
func Locale(name string) ([]byte, error) {
5775
return fileFromDir(path.Join("locale", name))
@@ -85,5 +103,11 @@ func fileFromDir(name string) ([]byte, error) {
85103
return ioutil.ReadFile(customPath)
86104
}
87105

88-
return Asset(name)
106+
f, err := Assets.Open(name)
107+
if err != nil {
108+
return nil, err
109+
}
110+
defer f.Close()
111+
112+
return ioutil.ReadAll(f)
89113
}

modules/public/main.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// +build ignore
2+
3+
package main
4+
5+
import (
6+
"log"
7+
"net/http"
8+
9+
"github.com/shurcooL/vfsgen"
10+
)
11+
12+
func main() {
13+
var fsPublic http.FileSystem = http.Dir("../../public")
14+
err := vfsgen.Generate(fsPublic, vfsgen.Options{
15+
PackageName: "public",
16+
BuildTags: "bindata",
17+
VariableName: "Assets",
18+
Filename: "bindata.go",
19+
})
20+
if err != nil {
21+
log.Fatal("%v", err)
22+
}
23+
}

modules/public/public.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,8 @@ import (
1717
"gopkg.in/macaron.v1"
1818
)
1919

20-
//go:generate go-bindata -tags "bindata" -ignore "\\.go|\\.less" -pkg "public" -o "bindata.go" ../../public/...
20+
//go:generate go run -mod=vendor main.go
2121
//go:generate go fmt bindata.go
22-
//go:generate sed -i.bak s/..\/..\/public\/// bindata.go
23-
//go:generate rm -f bindata.go.bak
2422

2523
// Options represents the available options to configure the macaron handler.
2624
type Options struct {

modules/public/static.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,12 @@
77
package public
88

99
import (
10-
"github.com/go-macaron/bindata"
1110
"gopkg.in/macaron.v1"
1211
)
1312

1413
// Static implements the macaron static handler for serving assets.
1514
func Static(opts *Options) macaron.Handler {
16-
opts.FileSystem = bindata.Static(bindata.Options{
17-
Asset: Asset,
18-
AssetDir: AssetDir,
19-
AssetInfo: AssetInfo,
20-
AssetNames: AssetNames,
21-
Prefix: "",
22-
})
15+
opts.FileSystem = Assets
2316
// we don't need to pass the directory, because the directory var is only
2417
// used when in the options there is no FileSystem.
2518
return opts.staticHandler("")

0 commit comments

Comments
 (0)