summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2019-06-03 05:43:47 +0800
committerLauris BH <lauris@nix.lv>2019-06-03 00:43:47 +0300
commit83b90e41999d30e4abb46f6bf0f1c3359cfd4d04 (patch)
tree4a15e9a42a850534a00346116da84153600a3027 /modules
parent8eba27c79257c6bc68cefbdffbb36d3596e6d3ee (diff)
downloadgitea-83b90e41999d30e4abb46f6bf0f1c3359cfd4d04.tar.gz
gitea-83b90e41999d30e4abb46f6bf0f1c3359cfd4d04.zip
Use vfsgen instead of go-bindata (#7080)
* use vfsgen instead of go-bindata * fix templates * fix fmt * vendor vsfgen
Diffstat (limited to 'modules')
-rw-r--r--modules/options/main.go23
-rw-r--r--modules/options/options.go4
-rw-r--r--modules/options/static.go28
-rw-r--r--modules/public/main.go23
-rw-r--r--modules/public/public.go4
-rw-r--r--modules/public/static.go9
-rw-r--r--modules/templates/main.go23
-rw-r--r--modules/templates/static.go18
-rw-r--r--modules/templates/templates.go4
9 files changed, 117 insertions, 19 deletions
diff --git a/modules/options/main.go b/modules/options/main.go
new file mode 100644
index 0000000000..0bc6c04e24
--- /dev/null
+++ b/modules/options/main.go
@@ -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)
+ }
+}
diff --git a/modules/options/options.go b/modules/options/options.go
index 4f0c69b335..723dd54585 100644
--- a/modules/options/options.go
+++ b/modules/options/options.go
@@ -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
diff --git a/modules/options/static.go b/modules/options/static.go
index 3301f45171..629901f740 100644
--- a/modules/options/static.go
+++ b/modules/options/static.go
@@ -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)
@@ -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))
@@ -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)
}
diff --git a/modules/public/main.go b/modules/public/main.go
new file mode 100644
index 0000000000..707dbe2b22
--- /dev/null
+++ b/modules/public/main.go
@@ -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)
+ }
+}
diff --git a/modules/public/public.go b/modules/public/public.go
index 2e004536f8..8362b42576 100644
--- a/modules/public/public.go
+++ b/modules/public/public.go
@@ -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 {
diff --git a/modules/public/static.go b/modules/public/static.go
index 10e32dbd10..054b9a806c 100644
--- a/modules/public/static.go
+++ b/modules/public/static.go
@@ -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("")
diff --git a/modules/templates/main.go b/modules/templates/main.go
new file mode 100644
index 0000000000..4460f58cbf
--- /dev/null
+++ b/modules/templates/main.go
@@ -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)
+ }
+}
diff --git a/modules/templates/static.go b/modules/templates/static.go
index e69e1cae48..3aabe17e4f 100644
--- a/modules/templates/static.go
+++ b/modules/templates/static.go
@@ -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
+}
diff --git a/modules/templates/templates.go b/modules/templates/templates.go
index 91c8db5228..e7fe3b2bfb 100644
--- a/modules/templates/templates.go
+++ b/modules/templates/templates.go
@@ -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