mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-25 11:22:16 +00:00
Use vfsgen instead of go-bindata (#7080)
* use vfsgen instead of go-bindata * fix templates * fix fmt * vendor vsfgen
This commit is contained in:
parent
8eba27c792
commit
83b90e4199
36 changed files with 1224 additions and 612 deletions
23
modules/options/main.go
Normal file
23
modules/options/main.go
Normal file
|
@ -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,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
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue