From 1004bf01495dbe15411d5af0f4dd317c2344c3ce Mon Sep 17 00:00:00 2001 From: Steven Hartland Date: Sat, 22 Apr 2023 08:49:42 +0100 Subject: [PATCH] feat: use standard library embed Use the standard library embed for internal files instead of esc and go-bindata which significantly simplifies the code and removes the need for 3rd party dependencies. Also: * Update go workflow with latest actions so we get caching. --- .github/workflows/go.yml | 27 +- README.md | 2 +- go.mod | 2 +- internal/render/README.md | 7 - internal/render/bindata/esc.go | 325 ----------------------- internal/render/bindata/helper.go | 23 -- internal/render/helpers.go | 1 - internal/render/render.go | 31 +-- templates/embed.go | 6 + templates/gen.go | 2 - templates/testify/call.tmpl | 1 - templates/testify/header.tmpl | 1 - templates/testify/inline.tmpl | 1 - templates/testify/inputs.tmpl | 1 - templates/testify/message.tmpl | 1 - templates/testify/results.tmpl | 1 - templates/tmpl.go | 427 ------------------------------ 17 files changed, 25 insertions(+), 834 deletions(-) delete mode 100755 internal/render/README.md delete mode 100644 internal/render/bindata/esc.go delete mode 100644 internal/render/bindata/helper.go create mode 100644 templates/embed.go delete mode 100644 templates/gen.go delete mode 120000 templates/testify/call.tmpl delete mode 120000 templates/testify/header.tmpl delete mode 120000 templates/testify/inline.tmpl delete mode 120000 templates/testify/inputs.tmpl delete mode 120000 templates/testify/message.tmpl delete mode 120000 templates/testify/results.tmpl delete mode 100644 templates/tmpl.go diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index f5ac7ae..5e73d9a 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -13,28 +13,17 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go: [ 1.16.x, 1.15.x, 1.14.x, 1.13.x, 1.12.x, 1.11.x, 1.10.x, 1.9.x ] - env: - GOPATH: ${{ github.workspace }} - GO111MODULE: auto - defaults: - run: - working-directory: ${{ env.GOPATH }}/src/github.com/cweill/gotests + go: [ 1.16.x, 1.19.x, 1.20.x ] steps: + - name: Check out code + uses: actions/checkout@v3 + - name: Set up Go 1.x - uses: actions/setup-go@v2 + uses: actions/setup-go@v4 with: go-version: ${{ matrix.go }} - - name: Check out code - uses: actions/checkout@v2 - with: - path: ${{ env.GOPATH }}/src/github.com/cweill/gotests - - - name: Get Dependencies (github.com/golang.org/x/tools/imports) - run: go get -v ./... - - name: Test run: | go test -v ./... @@ -42,9 +31,7 @@ jobs: - name: Coverage Dependencies if: matrix.go == '1.16.x' run: | - go get github.com/mattn/goveralls - go get -v ./... - + go install github.com/mattn/goveralls@latest - name: Coverage Reporting Generation if: matrix.go == '1.16.x' @@ -54,6 +41,6 @@ jobs: - name: Coverage - Sending Report to Coveral if: matrix.go == '1.16.x' - run: $GOPATH/bin/goveralls -coverprofile=coverage.cov -service=github + run: goveralls -coverprofile=coverage.cov -service=github env: COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index aeea963..5fd370d 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ The following shows `gotests` in action using the [official Sublime Text 3 plugi ## Installation -__Minimum Go version:__ Go 1.6 +__Minimum Go version:__ Go 1.16 Use [`go get`](https://golang.org/cmd/go/#hdr-Download_and_install_packages_and_dependencies) to install and update: diff --git a/go.mod b/go.mod index 2e5215b..ce643bd 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,4 @@ module github.com/cweill/gotests require golang.org/x/tools v0.0.0-20191109212701-97ad0ed33101 -go 1.6 +go 1.16 diff --git a/internal/render/README.md b/internal/render/README.md deleted file mode 100755 index 2430e9e..0000000 --- a/internal/render/README.md +++ /dev/null @@ -1,7 +0,0 @@ -bindata.go must be generated with https://github.com/jteeuwen/go-bindata. - -From the gotests root run `$ go generate ./...`. - -Or run `$ go-bindata -pkg=bindata -o "internal/render/bindata/bindata.go" internal/render/templates/`. - -During development run `$ go-bindata -pkg=bindata -o "internal/render/bindata/bindata.go" -debug internal/render/templates/` instead. \ No newline at end of file diff --git a/internal/render/bindata/esc.go b/internal/render/bindata/esc.go deleted file mode 100644 index b5ee552..0000000 --- a/internal/render/bindata/esc.go +++ /dev/null @@ -1,325 +0,0 @@ -// Code generated by "esc -o bindata/esc.go -pkg=bindata templates"; DO NOT EDIT. - -package bindata - -import ( - "bytes" - "compress/gzip" - "encoding/base64" - "fmt" - "io" - "io/ioutil" - "net/http" - "os" - "path" - "sync" - "time" -) - -type _escLocalFS struct{} - -var _escLocal _escLocalFS - -type _escStaticFS struct{} - -var _escStatic _escStaticFS - -type _escDirectory struct { - fs http.FileSystem - name string -} - -type _escFile struct { - compressed string - size int64 - modtime int64 - local string - isDir bool - - once sync.Once - data []byte - name string -} - -func (_escLocalFS) Open(name string) (http.File, error) { - f, present := _escData[path.Clean(name)] - if !present { - return nil, os.ErrNotExist - } - return os.Open(f.local) -} - -func (_escStaticFS) prepare(name string) (*_escFile, error) { - f, present := _escData[path.Clean(name)] - if !present { - return nil, os.ErrNotExist - } - var err error - f.once.Do(func() { - f.name = path.Base(name) - if f.size == 0 { - return - } - var gr *gzip.Reader - b64 := base64.NewDecoder(base64.StdEncoding, bytes.NewBufferString(f.compressed)) - gr, err = gzip.NewReader(b64) - if err != nil { - return - } - f.data, err = ioutil.ReadAll(gr) - }) - if err != nil { - return nil, err - } - return f, nil -} - -func (fs _escStaticFS) Open(name string) (http.File, error) { - f, err := fs.prepare(name) - if err != nil { - return nil, err - } - return f.File() -} - -func (dir _escDirectory) Open(name string) (http.File, error) { - return dir.fs.Open(dir.name + name) -} - -func (f *_escFile) File() (http.File, error) { - type httpFile struct { - *bytes.Reader - *_escFile - } - return &httpFile{ - Reader: bytes.NewReader(f.data), - _escFile: f, - }, nil -} - -func (f *_escFile) Close() error { - return nil -} - -func (f *_escFile) Readdir(count int) ([]os.FileInfo, error) { - if !f.isDir { - return nil, fmt.Errorf(" escFile.Readdir: '%s' is not directory", f.name) - } - - fis, ok := _escDirs[f.local] - if !ok { - return nil, fmt.Errorf(" escFile.Readdir: '%s' is directory, but we have no info about content of this dir, local=%s", f.name, f.local) - } - limit := count - if count <= 0 || limit > len(fis) { - limit = len(fis) - } - - if len(fis) == 0 && count > 0 { - return nil, io.EOF - } - - return fis[0:limit], nil -} - -func (f *_escFile) Stat() (os.FileInfo, error) { - return f, nil -} - -func (f *_escFile) Name() string { - return f.name -} - -func (f *_escFile) Size() int64 { - return f.size -} - -func (f *_escFile) Mode() os.FileMode { - return 0 -} - -func (f *_escFile) ModTime() time.Time { - return time.Unix(f.modtime, 0) -} - -func (f *_escFile) IsDir() bool { - return f.isDir -} - -func (f *_escFile) Sys() interface{} { - return f -} - -// FS returns a http.Filesystem for the embedded assets. If useLocal is true, -// the filesystem's contents are instead used. -func FS(useLocal bool) http.FileSystem { - if useLocal { - return _escLocal - } - return _escStatic -} - -// Dir returns a http.Filesystem for the embedded assets on a given prefix dir. -// If useLocal is true, the filesystem's contents are instead used. -func Dir(useLocal bool, name string) http.FileSystem { - if useLocal { - return _escDirectory{fs: _escLocal, name: name} - } - return _escDirectory{fs: _escStatic, name: name} -} - -// FSByte returns the named file from the embedded assets. If useLocal is -// true, the filesystem's contents are instead used. -func FSByte(useLocal bool, name string) ([]byte, error) { - if useLocal { - f, err := _escLocal.Open(name) - if err != nil { - return nil, err - } - b, err := ioutil.ReadAll(f) - _ = f.Close() - return b, err - } - f, err := _escStatic.prepare(name) - if err != nil { - return nil, err - } - return f.data, nil -} - -// FSMustByte is the same as FSByte, but panics if name is not present. -func FSMustByte(useLocal bool, name string) []byte { - b, err := FSByte(useLocal, name) - if err != nil { - panic(err) - } - return b -} - -// FSString is the string version of FSByte. -func FSString(useLocal bool, name string) (string, error) { - b, err := FSByte(useLocal, name) - return string(b), err -} - -// FSMustString is the string version of FSMustByte. -func FSMustString(useLocal bool, name string) string { - return string(FSMustByte(useLocal, name)) -} - -var _escData = map[string]*_escFile{ - - "/templates/call.tmpl": { - name: "call.tmpl", - local: "templates/call.tmpl", - size: 241, - modtime: 1613754073, - compressed: ` -H4sIAAAAAAAC/0SOQWrDQAxFryKMFy0YHaDQA3hTSlvatRjLrsCeFo2SEITuHsY4mdWHP2/el/vEs2SG -LtG6dhHuF7FfwA9OLGfW2sgM+c8Ax/JpekoWYYbunKf6eicBI1qLb7RxxJO7Ul4Yehmg5xVeXgHfSWlj -Yy2HvZeIAR5/296PitUbzJB0KU2/K+riTuPX9Z9xLN+kQpOkCMTG7vF85C0AAP//ZQi8iPEAAAA= -`, - }, - - "/templates/function.tmpl": { - name: "function.tmpl", - local: "templates/function.tmpl", - size: 2657, - modtime: 1616467003, - compressed: ` -H4sIAAAAAAAC/7RWTW/bRhA9U79iIjiBWCibuw0fGsQtcmhcyEZzCIpiLQ3VRVdLdXfoQFjsfy/2i1xK -pONLLyK5nI83894MZe0OG6EQlk2ntiRatXRuYe17uGrg+haYc4uFfwXWskc09IUf0LkVwU+EhoTas8ca -7KLyLt8F/Q1sg1sUz6idW1ThWDTAPpsH0t2WwmF/+otAuTPxrKLTEaEJJ2CCsY+brDVXezxzqKwNzx5k -gHc6YnrlXVDt0lOfMx8V92e3HpUv83eu+QEJdUgWoHG9HwErYF16hITh6AJdkXGc3zfU+KZbG3D4Vu+c -O/DjN0NaqP2fMbu1KA0692149gESKO+6Ui0l/9o5xQ8IMUIyTSgm+MpN4Go3kHbW98RRvPStDZBS4Tnk -JTMzLLzQ+6oKjfc/Ez4FARs0nSST83zlil7qfZ9yg9RpZe60blMPvnNFd1rDU9vKM8J8jz98gMf7T/fX -8PNuB5402HKDhgU+m1aDtZ6DVgN76J4iq5GRz+YL/wd3dR1gFRx7ijKtfyWS1kAU1RDpjaXGcLbAn3OM -ivI9lBKlczEI0c2Y+8xxNhxB8R7+emOtrxyCF7FNp1azsIlYeozg/dK4XBOTCPv7VT0G2Y/wnFpn9suF -BkMbg75ORwzGXDv3LmVLCmF/cNmhczaHmFk7lbUsrsFrIGJxDlixjNZDgGEJVROb6eIh5ZvYJbnMr1pQ -X/1ox1zfwrunE6FhH7umQW1fkzDJIMrzXslTOQ315fm9wtClGnpkhIej5ISw1HECl3DVBIEPb7Zcyng8 -h2JiDCvRJNbOgTkHqHVkdSrJTT80K2/35haUkLW/ErE83YlmYiFks1qWsQ5oDN9jKgW9BdzC2+c1ZPe3 -z8v1KL1Qx64vHrVeF8nqQRF5y43WVXhXDjM4p0PBeby2rSKhOhwG5MefuRc35KymQtd/bWkYnF5j7CF8 -RVb1TWESu1ou3EF30mDK8ZEbsS2+0D25V82UvvxQjjCUfZZC4TnRr8bzP+V/o7GRuCX2CfF492/H5aqP -sB4DqktEPXuv0WEGnMD+1kkSRzkCm/AMWv2BUGdBzv9zOtMp+IKiCbyP/2rcYpF1+l8AAAD//1pk1KJh -CgAA -`, - }, - - "/templates/header.tmpl": { - name: "header.tmpl", - local: "templates/header.tmpl", - size: 142, - modtime: 1616472631, - compressed: ` -H4sIAAAAAAAC/0TMMQ7CMAyF4d2nsDrBQC7BxIK4gkUebYXiViGb9e6OlAi6/bL1voiM1+rQaYFl1ImU -iGo+Q9N1KwXePmRE6g941gspuz3fNkMj0mMkKbKWfatNT4dw65cB3K2AHJO2/DhSzv/6BgAA///GzMM9 -jgAAAA== -`, - }, - - "/templates/inline.tmpl": { - name: "inline.tmpl", - local: "templates/inline.tmpl", - size: 49, - modtime: 1613735787, - compressed: ` -H4sIAAAAAAAC/6quTklNy8xLVVDKzMvJzEtVqq1VqK4uSc0tyEksSVVQSk7MyVFS0AOLpual1NYCAgAA -//+q60H/MQAAAA== -`, - }, - - "/templates/inputs.tmpl": { - name: "inputs.tmpl", - local: "templates/inputs.tmpl", - size: 177, - modtime: 1616467003, - compressed: ` -H4sIAAAAAAAC/0yNMaoDMQxE+38KsWz58QECOUCaEMgJFCwvLqwESVsJ3T1YpHAlzWN4416pdSbYOn9O -0y3CfW9wuUKZb2/Ab4PyPF9GarqyOw6qEWbFnbhGMA76h1/I3t7KQzrbLeUTCvJByVFwkJFoKlAOLe5J -5/TiWc/fNwAA//94+RPrsQAAAA== -`, - }, - - "/templates/message.tmpl": { - name: "message.tmpl", - local: "templates/message.tmpl", - size: 201, - modtime: 1613735787, - compressed: ` -H4sIAAAAAAAC/zyN4WqDQBCE//sUiyi0oPsAhT5A/xRpS/9f4mgW9GLuTkNY9t2DB/HXDDPDN6o9BvGg -ckaMbkRJrVmhKgP5ayL+XU8JMUWz+sakCt+bqd4lXYh/cIZsCHvCf48F/O+mFWZ8DPnbzTB7y0Tugvj0 -5Zd1B6oG50dQJQ1VmOjjk7hzwc1ICLmXgSoxa16/9XZws7wXqi1l+wwAAP//kC65UskAAAA= -`, - }, - - "/templates/results.tmpl": { - name: "results.tmpl", - local: "templates/results.tmpl", - size: 168, - modtime: 1613735787, - compressed: ` -H4sIAAAAAAAC/1yNTQrCQAyFr/Iosyw9gOBS3HsDoRkJlAy8ma5C7i6pRcFVfr4vee6rVDXBROn7NvoU -AXc+7SUoOqPIhssVy+ODI9y1omjEDHexNTf3NrBkc85a82DstH4jG1MW8uQ4hMbv0385A3/uUd8BAAD/ -/7BPz2GoAAAA -`, - }, - - "/templates": { - name: "templates", - local: `templates`, - isDir: true, - }, -} - -var _escDirs = map[string][]os.FileInfo{ - - "templates": { - _escData["/templates/call.tmpl"], - _escData["/templates/function.tmpl"], - _escData["/templates/header.tmpl"], - _escData["/templates/inline.tmpl"], - _escData["/templates/inputs.tmpl"], - _escData["/templates/message.tmpl"], - _escData["/templates/results.tmpl"], - }, -} diff --git a/internal/render/bindata/helper.go b/internal/render/bindata/helper.go deleted file mode 100644 index d73dba3..0000000 --- a/internal/render/bindata/helper.go +++ /dev/null @@ -1,23 +0,0 @@ -// Package bindata -// Helper with wrapper for backward compatibility with go-bindata -// used only AssetNames func, because only this func has no analog on esc -// -// the reason for changing go-bindata to esc - is: -// `go-bindata creator deleted their @github account and someone else created a new account with the same name.` -// -// https://github.com/jteeuwen/go-bindata/issues/5 -// https://twitter.com/francesc/status/961249107020001280 -// -// After research some of alternatives - `esc` - is looks like one of the best choice -// https://tech.townsourced.com/post/embedding-static-files-in-go/ - -package bindata - -// AssetNames returns the names of the assets. (for compatible with go-bindata) -func AssetNames() []string { - names := make([]string, 0, len(_escData)) - for name := range _escData { - names = append(names, name) - } - return names -} diff --git a/internal/render/helpers.go b/internal/render/helpers.go index 20af67b..ef476fe 100755 --- a/internal/render/helpers.go +++ b/internal/render/helpers.go @@ -1,6 +1,5 @@ package render -//go:generate esc -o bindata/esc.go -pkg=bindata templates import ( "fmt" "strings" diff --git a/internal/render/render.go b/internal/render/render.go index 4317420..807601b 100755 --- a/internal/render/render.go +++ b/internal/render/render.go @@ -1,17 +1,21 @@ package render import ( + "embed" "fmt" "io" + "io/fs" "io/ioutil" "path" "text/template" "github.com/cweill/gotests/internal/models" - "github.com/cweill/gotests/internal/render/bindata" "github.com/cweill/gotests/templates" ) +//go:embed templates/* +var data embed.FS + type Render struct { tmpls *template.Template } @@ -28,9 +32,7 @@ func New() *Render { } // default templates first - for _, name := range bindata.AssetNames() { - r.tmpls = template.Must(r.tmpls.Parse(bindata.FSMustString(false, name))) - } + r.tmpls = template.Must(r.tmpls.ParseFS(data, "templates/*.tmpl")) return &r } @@ -56,27 +58,14 @@ func (r *Render) LoadCustomTemplates(dir string) error { // LoadCustomTemplatesName allows to load in custom templates of a specified name from the templates directory. func (r *Render) LoadCustomTemplatesName(name string) error { - f, err := templates.Dir(false, "/").Open(name) + fileSystem, err := fs.Sub(templates.FS, name) if err != nil { - return fmt.Errorf("templates.Open: %v", err) + return fmt.Errorf("templates.Sub: %w", err) } - files, err := f.Readdir(nFile) + r.tmpls, err = r.tmpls.ParseFS(fileSystem, "*.tmpl") if err != nil { - return fmt.Errorf("f.Readdir: %v", err) - } - - for _, f := range files { - text, err := templates.FSString(false, path.Join("/", name, f.Name())) - if err != nil { - return fmt.Errorf("templates.FSString: %v", err) - } - - if tmpls, err := r.tmpls.Parse(text); err != nil { - return fmt.Errorf("tmpls.Parse: %v", err) - } else { - r.tmpls = tmpls - } + return fmt.Errorf("templates.ParseFS: %w", err) } return nil diff --git a/templates/embed.go b/templates/embed.go new file mode 100644 index 0000000..dd03d6a --- /dev/null +++ b/templates/embed.go @@ -0,0 +1,6 @@ +package templates + +import "embed" + +//go:embed test/* test_empty/* testify/* +var FS embed.FS diff --git a/templates/gen.go b/templates/gen.go deleted file mode 100644 index 74f9a26..0000000 --- a/templates/gen.go +++ /dev/null @@ -1,2 +0,0 @@ -//go:generate esc -include=.*\.tmpl -o=tmpl.go -pkg=templates ./ -package templates diff --git a/templates/testify/call.tmpl b/templates/testify/call.tmpl deleted file mode 120000 index d5b800c..0000000 --- a/templates/testify/call.tmpl +++ /dev/null @@ -1 +0,0 @@ -../../internal/render/templates/call.tmpl \ No newline at end of file diff --git a/templates/testify/header.tmpl b/templates/testify/header.tmpl deleted file mode 120000 index a5ca888..0000000 --- a/templates/testify/header.tmpl +++ /dev/null @@ -1 +0,0 @@ -../../internal/render/templates/header.tmpl \ No newline at end of file diff --git a/templates/testify/inline.tmpl b/templates/testify/inline.tmpl deleted file mode 120000 index 6714127..0000000 --- a/templates/testify/inline.tmpl +++ /dev/null @@ -1 +0,0 @@ -../../internal/render/templates/inline.tmpl \ No newline at end of file diff --git a/templates/testify/inputs.tmpl b/templates/testify/inputs.tmpl deleted file mode 120000 index 4d27026..0000000 --- a/templates/testify/inputs.tmpl +++ /dev/null @@ -1 +0,0 @@ -../../internal/render/templates/inputs.tmpl \ No newline at end of file diff --git a/templates/testify/message.tmpl b/templates/testify/message.tmpl deleted file mode 120000 index 27a6554..0000000 --- a/templates/testify/message.tmpl +++ /dev/null @@ -1 +0,0 @@ -../../internal/render/templates/message.tmpl \ No newline at end of file diff --git a/templates/testify/results.tmpl b/templates/testify/results.tmpl deleted file mode 120000 index a159a24..0000000 --- a/templates/testify/results.tmpl +++ /dev/null @@ -1 +0,0 @@ -../../internal/render/templates/results.tmpl \ No newline at end of file diff --git a/templates/tmpl.go b/templates/tmpl.go deleted file mode 100644 index 3a8bce2..0000000 --- a/templates/tmpl.go +++ /dev/null @@ -1,427 +0,0 @@ -// Code generated by "esc -include=.*\.tmpl -o=tmpl.go -pkg=templates ./"; DO NOT EDIT. - -package templates - -import ( - "bytes" - "compress/gzip" - "encoding/base64" - "fmt" - "io" - "io/ioutil" - "net/http" - "os" - "path" - "sync" - "time" -) - -type _escLocalFS struct{} - -var _escLocal _escLocalFS - -type _escStaticFS struct{} - -var _escStatic _escStaticFS - -type _escDirectory struct { - fs http.FileSystem - name string -} - -type _escFile struct { - compressed string - size int64 - modtime int64 - local string - isDir bool - - once sync.Once - data []byte - name string -} - -func (_escLocalFS) Open(name string) (http.File, error) { - f, present := _escData[path.Clean(name)] - if !present { - return nil, os.ErrNotExist - } - return os.Open(f.local) -} - -func (_escStaticFS) prepare(name string) (*_escFile, error) { - f, present := _escData[path.Clean(name)] - if !present { - return nil, os.ErrNotExist - } - var err error - f.once.Do(func() { - f.name = path.Base(name) - if f.size == 0 { - return - } - var gr *gzip.Reader - b64 := base64.NewDecoder(base64.StdEncoding, bytes.NewBufferString(f.compressed)) - gr, err = gzip.NewReader(b64) - if err != nil { - return - } - f.data, err = ioutil.ReadAll(gr) - }) - if err != nil { - return nil, err - } - return f, nil -} - -func (fs _escStaticFS) Open(name string) (http.File, error) { - f, err := fs.prepare(name) - if err != nil { - return nil, err - } - return f.File() -} - -func (dir _escDirectory) Open(name string) (http.File, error) { - return dir.fs.Open(dir.name + name) -} - -func (f *_escFile) File() (http.File, error) { - type httpFile struct { - *bytes.Reader - *_escFile - } - return &httpFile{ - Reader: bytes.NewReader(f.data), - _escFile: f, - }, nil -} - -func (f *_escFile) Close() error { - return nil -} - -func (f *_escFile) Readdir(count int) ([]os.FileInfo, error) { - if !f.isDir { - return nil, fmt.Errorf(" escFile.Readdir: '%s' is not directory", f.name) - } - - fis, ok := _escDirs[f.local] - if !ok { - return nil, fmt.Errorf(" escFile.Readdir: '%s' is directory, but we have no info about content of this dir, local=%s", f.name, f.local) - } - limit := count - if count <= 0 || limit > len(fis) { - limit = len(fis) - } - - if len(fis) == 0 && count > 0 { - return nil, io.EOF - } - - return fis[0:limit], nil -} - -func (f *_escFile) Stat() (os.FileInfo, error) { - return f, nil -} - -func (f *_escFile) Name() string { - return f.name -} - -func (f *_escFile) Size() int64 { - return f.size -} - -func (f *_escFile) Mode() os.FileMode { - return 0 -} - -func (f *_escFile) ModTime() time.Time { - return time.Unix(f.modtime, 0) -} - -func (f *_escFile) IsDir() bool { - return f.isDir -} - -func (f *_escFile) Sys() interface{} { - return f -} - -// FS returns a http.Filesystem for the embedded assets. If useLocal is true, -// the filesystem's contents are instead used. -func FS(useLocal bool) http.FileSystem { - if useLocal { - return _escLocal - } - return _escStatic -} - -// Dir returns a http.Filesystem for the embedded assets on a given prefix dir. -// If useLocal is true, the filesystem's contents are instead used. -func Dir(useLocal bool, name string) http.FileSystem { - if useLocal { - return _escDirectory{fs: _escLocal, name: name} - } - return _escDirectory{fs: _escStatic, name: name} -} - -// FSByte returns the named file from the embedded assets. If useLocal is -// true, the filesystem's contents are instead used. -func FSByte(useLocal bool, name string) ([]byte, error) { - if useLocal { - f, err := _escLocal.Open(name) - if err != nil { - return nil, err - } - b, err := ioutil.ReadAll(f) - _ = f.Close() - return b, err - } - f, err := _escStatic.prepare(name) - if err != nil { - return nil, err - } - return f.data, nil -} - -// FSMustByte is the same as FSByte, but panics if name is not present. -func FSMustByte(useLocal bool, name string) []byte { - b, err := FSByte(useLocal, name) - if err != nil { - panic(err) - } - return b -} - -// FSString is the string version of FSByte. -func FSString(useLocal bool, name string) (string, error) { - b, err := FSByte(useLocal, name) - return string(b), err -} - -// FSMustString is the string version of FSMustByte. -func FSMustString(useLocal bool, name string) string { - return string(FSMustByte(useLocal, name)) -} - -var _escData = map[string]*_escFile{ - - "/test/call.tmpl": { - name: "call.tmpl", - local: "test/call.tmpl", - size: 0, - modtime: 1615633710, - compressed: ` -H4sIAAAAAAAC/wEAAP//AAAAAAAAAAA= -`, - }, - - "/test/function.tmpl": { - name: "function.tmpl", - local: "test/function.tmpl", - size: 19, - modtime: 1615633710, - compressed: ` -H4sIAAAAAAAC/6qu1tdSSFRIzs/NTc0rUdDSr+UCBAAA//+6o7WcEwAAAA== -`, - }, - - "/test/header.tmpl": { - name: "header.tmpl", - local: "test/header.tmpl", - size: 0, - modtime: 1615633710, - compressed: ` -H4sIAAAAAAAC/wEAAP//AAAAAAAAAAA= -`, - }, - - "/test/inline.tmpl": { - name: "inline.tmpl", - local: "test/inline.tmpl", - size: 0, - modtime: 1615633710, - compressed: ` -H4sIAAAAAAAC/wEAAP//AAAAAAAAAAA= -`, - }, - - "/test/inputs.tmpl": { - name: "inputs.tmpl", - local: "test/inputs.tmpl", - size: 0, - modtime: 1615633710, - compressed: ` -H4sIAAAAAAAC/wEAAP//AAAAAAAAAAA= -`, - }, - - "/test/message.tmpl": { - name: "message.tmpl", - local: "test/message.tmpl", - size: 0, - modtime: 1615633710, - compressed: ` -H4sIAAAAAAAC/wEAAP//AAAAAAAAAAA= -`, - }, - - "/test/results.tmpl": { - name: "results.tmpl", - local: "test/results.tmpl", - size: 0, - modtime: 1615633710, - compressed: ` -H4sIAAAAAAAC/wEAAP//AAAAAAAAAAA= -`, - }, - - "/testify/call.tmpl": { - name: "call.tmpl", - local: "testify/call.tmpl", - size: 241, - modtime: 1613754073, - compressed: ` -H4sIAAAAAAAC/0SOQWrDQAxFryKMFy0YHaDQA3hTSlvatRjLrsCeFo2SEITuHsY4mdWHP2/el/vEs2SG -LtG6dhHuF7FfwA9OLGfW2sgM+c8Ax/JpekoWYYbunKf6eicBI1qLb7RxxJO7Ul4Yehmg5xVeXgHfSWlj -Yy2HvZeIAR5/296PitUbzJB0KU2/K+riTuPX9Z9xLN+kQpOkCMTG7vF85C0AAP//ZQi8iPEAAAA= -`, - }, - - "/testify/function.tmpl": { - name: "function.tmpl", - local: "testify/function.tmpl", - size: 2798, - modtime: 1616467003, - compressed: ` -H4sIAAAAAAAC/5xWUW/cNgx+tn8FYQTFebiq7yn60GHtkJemSIL1oRgG9UzfjPl0N4necBD43wdRlu3z -2VnTPOQsyiQ/8qM+y/sK68YgFNo5tNQcTQGvmXMiNVg2tAXvmxrUvWnPD0idNe6DtUfL7D3h4dRqQih2 -um0LUMGIrUNmtNZ7NBVz7v1raGo4WtiYI4F67L4ROnIlqM+2MXRnTh05SQ0AsIX6QOrxFLbqTTHNckDn -9B4lURGAjVuNBJGdUjKiqSTksGLO83wsGv/udFswx1LVh7CUSv8HJ3PdF5bqm0Y9uH0Rdr4nDmzhB6p7 -JnndmZ3Q2Df9pobbd8Enz8MWeK+e0NEnfUDmDcFPAVZj9uqpBJ9nweXfhv4E9YA7bP5By5xnWU+funOP -ZLsdiXGwfmywrVy0ZXQ+IdRiAScvh7j921abPc4cMu9lHUAKvPMJ+62RtbAacibT5Hn2GFCFMj9rqw9I -aCWZQNN2fwFsAuvaQxKK6QrdJONlfuE5NN17wRFaXTEf9OmrI9uY/e8xezolX8d1CNCDCq5xdMS/ZDb6 -gBAjJOKzNb5SE7SpRtJmfe85ij9DawVSX3gKec3MCgvP9D7LpPHh34LPhIAHdF1LLuX5og091/sh5aUu -ScIkYJDOd9h7n6wfO7Ob8Rha/+YNPN3/cn8L76sKApew0w6dEprro41SuDna8VD3RN25T/ovrMpS0E6o -D8wltv/oudsCURySyHrsQAznJ2WlHBe1hta2LbbMMQjR28uRSNSnFy+gBI/w+9Z7UUjxIvXQmc0qbCLV -LyP4oCXX6rGIcHjelJcgh5O9NsQrsnM1mtJGGbvzCeVlbZlfDSoZ7b/ptkNmn0KsqFHmvYrqeAtEKh4P -NdGo7Rhg1KZsQbCuFn2+BYlJZX6xDQ3VX0jP7Tt49e1M6NTPXV2j9d+TsB+DOJ7zj3d5bb83KF0qYUA2 -fn9sPJgF3NQy4PMPfzCvoZifTpj9TaNNbiKrIdf0YqmVsPA3zRcvAZIr3HSI1Kg64Qs8cKAeRXzDGE8+ -2G4ffcuRj6ihy3kF3k291PUVn5find4Y2sZgfHUF8xrIZ2p4KZ5fjxTvLC8DMByt1RGfSyQwA5cwvfhl -nHO4HUWX/wIAAP//vN7yje4KAAA= -`, - }, - - "/testify/header.tmpl": { - name: "header.tmpl", - local: "testify/header.tmpl", - size: 142, - modtime: 1616472631, - compressed: ` -H4sIAAAAAAAC/0TMMQ7CMAyF4d2nsDrBQC7BxIK4gkUebYXiViGb9e6OlAi6/bL1voiM1+rQaYFl1ImU -iGo+Q9N1KwXePmRE6g941gspuz3fNkMj0mMkKbKWfatNT4dw65cB3K2AHJO2/DhSzv/6BgAA///GzMM9 -jgAAAA== -`, - }, - - "/testify/inline.tmpl": { - name: "inline.tmpl", - local: "testify/inline.tmpl", - size: 49, - modtime: 1613735787, - compressed: ` -H4sIAAAAAAAC/6quTklNy8xLVVDKzMvJzEtVqq1VqK4uSc0tyEksSVVQSk7MyVFS0AOLpual1NYCAgAA -//+q60H/MQAAAA== -`, - }, - - "/testify/inputs.tmpl": { - name: "inputs.tmpl", - local: "testify/inputs.tmpl", - size: 177, - modtime: 1616467003, - compressed: ` -H4sIAAAAAAAC/0yNMaoDMQxE+38KsWz58QECOUCaEMgJFCwvLqwESVsJ3T1YpHAlzWN4416pdSbYOn9O -0y3CfW9wuUKZb2/Ab4PyPF9GarqyOw6qEWbFnbhGMA76h1/I3t7KQzrbLeUTCvJByVFwkJFoKlAOLe5J -5/TiWc/fNwAA//94+RPrsQAAAA== -`, - }, - - "/testify/message.tmpl": { - name: "message.tmpl", - local: "testify/message.tmpl", - size: 201, - modtime: 1613735787, - compressed: ` -H4sIAAAAAAAC/zyN4WqDQBCE//sUiyi0oPsAhT5A/xRpS/9f4mgW9GLuTkNY9t2DB/HXDDPDN6o9BvGg -ckaMbkRJrVmhKgP5ayL+XU8JMUWz+sakCt+bqd4lXYh/cIZsCHvCf48F/O+mFWZ8DPnbzTB7y0Tugvj0 -5Zd1B6oG50dQJQ1VmOjjk7hzwc1ICLmXgSoxa16/9XZws7wXqi1l+wwAAP//kC65UskAAAA= -`, - }, - - "/testify/results.tmpl": { - name: "results.tmpl", - local: "testify/results.tmpl", - size: 168, - modtime: 1613735787, - compressed: ` -H4sIAAAAAAAC/1yNTQrCQAyFr/Iosyw9gOBS3HsDoRkJlAy8ma5C7i6pRcFVfr4vee6rVDXBROn7NvoU -AXc+7SUoOqPIhssVy+ODI9y1omjEDHexNTf3NrBkc85a82DstH4jG1MW8uQ4hMbv0385A3/uUd8BAAD/ -/7BPz2GoAAAA -`, - }, - - "/": { - name: "/", - local: `./`, - isDir: true, - }, - - "/test": { - name: "test", - local: `test`, - isDir: true, - }, - - "/test_empty": { - name: "test_empty", - local: `test_empty`, - isDir: true, - }, - - "/testify": { - name: "testify", - local: `testify`, - isDir: true, - }, -} - -var _escDirs = map[string][]os.FileInfo{ - - "./": {}, - - "test": { - _escData["/test/call.tmpl"], - _escData["/test/function.tmpl"], - _escData["/test/header.tmpl"], - _escData["/test/inline.tmpl"], - _escData["/test/inputs.tmpl"], - _escData["/test/message.tmpl"], - _escData["/test/results.tmpl"], - }, - - "test_empty": {}, - - "testify": { - _escData["/testify/call.tmpl"], - _escData["/testify/function.tmpl"], - _escData["/testify/header.tmpl"], - _escData["/testify/inline.tmpl"], - _escData["/testify/inputs.tmpl"], - _escData["/testify/message.tmpl"], - _escData["/testify/results.tmpl"], - }, -}