Skip to content

Commit

Permalink
Use vfsgen instead of go-bindata (go-gitea#7080)
Browse files Browse the repository at this point in the history
* use vfsgen instead of go-bindata

* fix templates

* fix fmt

* vendor vsfgen
  • Loading branch information
lunny authored and lafriks committed Jun 2, 2019
1 parent 8eba27c commit 83b90e4
Show file tree
Hide file tree
Showing 36 changed files with 1,224 additions and 612 deletions.
5 changes: 1 addition & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,7 @@ vet:

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

.PHONY: generate-swagger
generate-swagger:
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ require (
github.com/denisenkom/go-mssqldb v0.0.0-20181014144952-4e0d7dc8888f
github.com/dgrijalva/jwt-go v0.0.0-20161101193935-9ed569b5d1ac
github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712 // indirect
github.com/elazarl/go-bindata-assetfs v0.0.0-20151224045452-57eb5e1fc594 // indirect
github.com/emirpasic/gods v1.12.0
github.com/etcd-io/bbolt v1.3.2 // indirect
github.com/ethantkoenig/rupture v0.0.0-20180203182544-0a76f03a811a
Expand All @@ -44,7 +43,6 @@ require (
github.com/facebookgo/subset v0.0.0-20150612182917-8dac2c3c4870 // indirect
github.com/glycerine/go-unsnap-stream v0.0.0-20180323001048-9f0cb55181dd // indirect
github.com/glycerine/goconvey v0.0.0-20190315024820-982ee783a72e // indirect
github.com/go-macaron/bindata v0.0.0-20161222093048-85786f57eee3
github.com/go-macaron/binding v0.0.0-20160711225916-9440f336b443
github.com/go-macaron/cache v0.0.0-20151013081102-561735312776
github.com/go-macaron/captcha v0.0.0-20151123225153-8aa5919789ab
Expand Down Expand Up @@ -103,7 +101,9 @@ require (
github.com/saintfish/chardet v0.0.0-20120816061221-3af4cd4741ca // indirect
github.com/satori/go.uuid v1.2.0
github.com/sergi/go-diff v1.0.0
github.com/shurcooL/httpfs v0.0.0-20190527155220-6a4d4a70508b // indirect
github.com/shurcooL/sanitized_anchor_name v0.0.0-20160918041101-1dba4b3954bc // indirect
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd
github.com/siddontang/go-snappy v0.0.0-20140704025258-d8f7bb82a96d // indirect
github.com/smartystreets/goconvey v0.0.0-20190306220146-200a235640ff // indirect
github.com/steveyen/gtreap v0.0.0-20150807155958-0abe01ef9be2 // indirect
Expand Down
9 changes: 5 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ github.com/dgrijalva/jwt-go v0.0.0-20161101193935-9ed569b5d1ac h1:xrQJVwQCGqDvOO
github.com/dgrijalva/jwt-go v0.0.0-20161101193935-9ed569b5d1ac/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712 h1:aaQcKT9WumO6JEJcRyTqFVq4XUZiUcKR2/GI31TOcz8=
github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
github.com/elazarl/go-bindata-assetfs v0.0.0-20151224045452-57eb5e1fc594 h1:McZ/pt/pP/XAbLMDQGzm/iQUwW6OXmKVbFtmH9klWmc=
github.com/elazarl/go-bindata-assetfs v0.0.0-20151224045452-57eb5e1fc594/go.mod h1:v+YaWX3bdea5J/mo8dSETolEo7R71Vk1u8bnjau5yw4=
github.com/emirpasic/gods v1.9.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
github.com/emirpasic/gods v1.12.0 h1:QAUIPSaCu4G+POclxeqb3F+WPpdKqFGlw36+yOzGlrg=
github.com/emirpasic/gods v1.12.0/go.mod h1:YfzfFFoVP/catgzJb4IKIqXjX78Ha8FMSDh3ymbK86o=
Expand Down Expand Up @@ -97,8 +95,6 @@ github.com/glycerine/go-unsnap-stream v0.0.0-20180323001048-9f0cb55181dd h1:r04M
github.com/glycerine/go-unsnap-stream v0.0.0-20180323001048-9f0cb55181dd/go.mod h1:/20jfyN9Y5QPEAprSgKAUr+glWDY39ZiUEAYOEv5dsE=
github.com/glycerine/goconvey v0.0.0-20190315024820-982ee783a72e h1:SiEs4J3BKVIeaWrH3tKaz3QLZhJ68iJ/A4xrzIoE5+Y=
github.com/glycerine/goconvey v0.0.0-20190315024820-982ee783a72e/go.mod h1:Ogl1Tioa0aV7gstGFO7KhffUsb9M4ydbEbbxpcEDc24=
github.com/go-macaron/bindata v0.0.0-20161222093048-85786f57eee3 h1:n0H90987ZwasTc9r/RnuaU1G5ePfzLG6Bkc1cY3KqnY=
github.com/go-macaron/bindata v0.0.0-20161222093048-85786f57eee3/go.mod h1:NkmXhFuAlCOqgV5EWhU1DKLrgztCEIVXGmr2DZv/+sk=
github.com/go-macaron/binding v0.0.0-20160711225916-9440f336b443 h1:i801KPR7j76uRMLLlGVyb0hiYbgX1FM5+ur81TJWzIw=
github.com/go-macaron/binding v0.0.0-20160711225916-9440f336b443/go.mod h1:u+H6rwW+HQwUL+w5uaEJSpIlVZDye1o9MB4Su0JfRfM=
github.com/go-macaron/cache v0.0.0-20151013081102-561735312776 h1:UYIHS1r0WotqB5cIa0PAiV0m6GzD9rDBcn4alp5JgCw=
Expand Down Expand Up @@ -282,8 +278,12 @@ github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24 h1:pntxY8Ary0t43dCZ5dqY4YTJCObLY1kIXl0uzMv+7DE=
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9NzErvs504Cn4c5DxATwIqPbtswREoFCre64PpcG4=
github.com/shurcooL/httpfs v0.0.0-20190527155220-6a4d4a70508b h1:4kg1wyftSKxLtnPAvcRWakIPpokB9w780/KwrNLnfPA=
github.com/shurcooL/httpfs v0.0.0-20190527155220-6a4d4a70508b/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg=
github.com/shurcooL/sanitized_anchor_name v0.0.0-20160918041101-1dba4b3954bc h1:3wIrJvFb3Pf6B/2mDBnN1G5IfUVev4X5apadQlWOczE=
github.com/shurcooL/sanitized_anchor_name v0.0.0-20160918041101-1dba4b3954bc/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd h1:ug7PpSOB5RBPK1Kg6qskGBoP3Vnj/aNYFTznWvlkGo0=
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw=
github.com/siddontang/go-snappy v0.0.0-20140704025258-d8f7bb82a96d h1:qQWKKOvHN7Q9c6GdmUteCef2F9ubxMpxY1IKwpIKz68=
github.com/siddontang/go-snappy v0.0.0-20140704025258-d8f7bb82a96d/go.mod h1:vq0tzqLRu6TS7Id0wMo2N5QzJoKedVeovOpHjnykSzY=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
Expand Down Expand Up @@ -348,6 +348,7 @@ golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e h1:nFYrTHrdrAOpShe27kaFHjsqY
golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635 h1:2eB4G6bDQDeP69ZXbOKC00S2Kf6TIiRS+DzfKsKeQU0=
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.2.0 h1:S0iUepdCWODXRvtE+gcRDd15L+k+k1AiHlMiMjefH24=
Expand Down
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import (
_ "code.gitea.io/gitea/modules/markup/markdown"
_ "code.gitea.io/gitea/modules/markup/orgmode"

// for embed
_ "github.com/shurcooL/vfsgen"

"github.com/urfave/cli"
)

Expand Down
23 changes: 23 additions & 0 deletions modules/options/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// +build ignore

package main

import (
"log"
"net/http"

"github.com/shurcooL/vfsgen"
)

func main() {
var fsTemplates http.FileSystem = http.Dir("../../options")
err := vfsgen.Generate(fsTemplates, vfsgen.Options{
PackageName: "options",
BuildTags: "bindata",
VariableName: "Assets",
Filename: "bindata.go",
})
if err != nil {
log.Fatal("%v", err)
}
}
4 changes: 1 addition & 3 deletions modules/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

package options

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

type directorySet map[string][]string

Expand Down
28 changes: 26 additions & 2 deletions modules/options/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func Dir(name string) ([]string, error) {
result = append(result, files...)
}

files, err := AssetDir(path.Join("..", "..", "options", name))
files, err := AssetDir(name)

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

func AssetDir(dirName string) ([]string, error) {
d, err := Assets.Open(dirName)
if err != nil {
return nil, err
}
defer d.Close()

files, err := d.Readdir(-1)
if err != nil {
return nil, err
}
var results = make([]string, 0, len(files))
for _, file := range files {
results = append(results, file.Name())
}
return results, nil
}

// Locale reads the content of a specific locale from bindata or custom path.
func Locale(name string) ([]byte, error) {
return fileFromDir(path.Join("locale", name))
Expand Down Expand Up @@ -85,5 +103,11 @@ func fileFromDir(name string) ([]byte, error) {
return ioutil.ReadFile(customPath)
}

return Asset(name)
f, err := Assets.Open(name)
if err != nil {
return nil, err
}
defer f.Close()

return ioutil.ReadAll(f)
}
23 changes: 23 additions & 0 deletions modules/public/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// +build ignore

package main

import (
"log"
"net/http"

"github.com/shurcooL/vfsgen"
)

func main() {
var fsPublic http.FileSystem = http.Dir("../../public")
err := vfsgen.Generate(fsPublic, vfsgen.Options{
PackageName: "public",
BuildTags: "bindata",
VariableName: "Assets",
Filename: "bindata.go",
})
if err != nil {
log.Fatal("%v", err)
}
}
4 changes: 1 addition & 3 deletions modules/public/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,8 @@ import (
"gopkg.in/macaron.v1"
)

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

// Options represents the available options to configure the macaron handler.
type Options struct {
Expand Down
9 changes: 1 addition & 8 deletions modules/public/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,12 @@
package public

import (
"github.com/go-macaron/bindata"
"gopkg.in/macaron.v1"
)

// Static implements the macaron static handler for serving assets.
func Static(opts *Options) macaron.Handler {
opts.FileSystem = bindata.Static(bindata.Options{
Asset: Asset,
AssetDir: AssetDir,
AssetInfo: AssetInfo,
AssetNames: AssetNames,
Prefix: "",
})
opts.FileSystem = Assets
// we don't need to pass the directory, because the directory var is only
// used when in the options there is no FileSystem.
return opts.staticHandler("")
Expand Down
23 changes: 23 additions & 0 deletions modules/templates/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// +build ignore

package main

import (
"log"
"net/http"

"github.com/shurcooL/vfsgen"
)

func main() {
var fsTemplates http.FileSystem = http.Dir("../../templates")
err := vfsgen.Generate(fsTemplates, vfsgen.Options{
PackageName: "templates",
BuildTags: "bindata",
VariableName: "Assets",
Filename: "bindata.go",
})
if err != nil {
log.Fatal("%v", err)
}
}
18 changes: 18 additions & 0 deletions modules/templates/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,21 @@ func Mailer() *template.Template {

return templates
}

func Asset(name string) ([]byte, error) {
f, err := Assets.Open("/" + name)
if err != nil {
return nil, err
}
defer f.Close()
return ioutil.ReadAll(f)
}

func AssetNames() []string {
realFS := Assets.(vfsgen۰FS)
var results = make([]string, 0, len(realFS))
for k := range realFS {
results = append(results, k[1:])
}
return results
}
4 changes: 1 addition & 3 deletions modules/templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@

package templates

//go:generate go-bindata -tags "bindata" -ignore "\\.go" -pkg "templates" -o "bindata.go" ../../templates/...
//go:generate go run -mod=vendor main.go
//go:generate go fmt bindata.go
//go:generate sed -i.bak s/..\/..\/templates\/// bindata.go
//go:generate rm -f bindata.go.bak
1 change: 0 additions & 1 deletion snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ parts:
build: |
export PATH=$SNAPCRAFT_PART_INSTALL/../go/bin/:$SNAPCRAFT_PART_INSTALL/../../go/install/bin:$PATH
export GOPATH=$SNAPCRAFT_PART_INSTALL/../go
go get -u github.com/jteeuwen/go-bindata/...
cd $GOPATH/src/code.gitea.io/gitea
TAGS="bindata sqlite sqlite_unlock_notify pam cert" make generate build
install: |
Expand Down
23 changes: 0 additions & 23 deletions vendor/github.com/elazarl/go-bindata-assetfs/LICENSE

This file was deleted.

46 changes: 0 additions & 46 deletions vendor/github.com/elazarl/go-bindata-assetfs/README.md

This file was deleted.

Loading

0 comments on commit 83b90e4

Please sign in to comment.