Implements writing of TOC file. Refactors code for debug and release
writers. Adds output examples for various output modes.
This commit is contained in:
parent
efd0c57cfd
commit
12a480432a
45
convert.go
45
convert.go
|
@ -34,54 +34,17 @@ func Translate(c *Config, pf ProgressFunc) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// Open output files.
|
||||
debug, release, err := openOutput(c.Output)
|
||||
err = writeDebug(c, toc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer func() {
|
||||
debug.Close()
|
||||
release.Close()
|
||||
}()
|
||||
|
||||
// Prepare files -- write package header and build tags.
|
||||
writeDebugHeader(debug, c)
|
||||
writeReleaseHeader(release, c)
|
||||
|
||||
// Convert assets and write them to the output files.
|
||||
var current int
|
||||
for i := range toc {
|
||||
if pf != nil {
|
||||
current++
|
||||
if pf(toc[i].Path, current, len(toc)) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
writeDebug(debug, c, &toc[i])
|
||||
writeRelease(release, c, &toc[i])
|
||||
}
|
||||
|
||||
// Generate TOC file.
|
||||
return nil
|
||||
}
|
||||
|
||||
// openOutput opens two output files. One for debug code and
|
||||
// one for release code.
|
||||
func openOutput(dir string) (*os.File, *os.File, error) {
|
||||
debug, err := os.Create(filepath.Join(dir, "bindata_debug.go"))
|
||||
err = writeRelease(c, toc)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
release, err := os.Create(filepath.Join(dir, "bindata_release.go"))
|
||||
if err != nil {
|
||||
debug.Close()
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
return debug, release, nil
|
||||
return writeTOC(c, toc)
|
||||
}
|
||||
|
||||
// fillTOC recursively finds all the file paths in the given directory tree.
|
||||
|
|
53
debug.go
53
debug.go
|
@ -7,25 +7,60 @@ package bindata
|
|||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// writeDebug writes the debug code file.
|
||||
func writeDebug(c *Config, toc []Asset) error {
|
||||
fd, err := os.Create(filepath.Join(c.Output, "bindata_debug.go"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer fd.Close()
|
||||
|
||||
err = writeDebugHeader(fd, c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for i := range toc {
|
||||
err = writeDebugAsset(fd, c, &toc[i])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// writeDebugHeader writes output file headers.
|
||||
// This targets debug builds.
|
||||
func writeDebugHeader(w io.Writer, c *Config) {
|
||||
func writeDebugHeader(w io.Writer, c *Config) error {
|
||||
var err error
|
||||
|
||||
// Write build tags, if applicable.
|
||||
if len(c.Tags) > 0 {
|
||||
fmt.Fprintf(w, "// +build !release %s\n\n", c.Tags)
|
||||
_, err = fmt.Fprintf(w, "// +build !release %s\n\n", c.Tags)
|
||||
} else {
|
||||
fmt.Fprintf(w, "// +build !release\n\n")
|
||||
_, err = fmt.Fprintf(w, "// +build !release\n\n")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Write package declaration
|
||||
fmt.Fprintf(w, "package %s\n\n", c.Package)
|
||||
_, err = fmt.Fprintf(w, "package %s\n\n", c.Package)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Define packages we need to import.
|
||||
// And add the asset_read function. This is called
|
||||
// from asset-specific functions.
|
||||
fmt.Fprintf(w, `import (
|
||||
_, err = fmt.Fprintf(w, `import (
|
||||
"bytes"
|
||||
"io"
|
||||
"log"
|
||||
|
@ -52,13 +87,14 @@ func bindata_read(path, name string) []byte {
|
|||
}
|
||||
|
||||
`)
|
||||
return err
|
||||
}
|
||||
|
||||
// writeDebug write a debug entry for the given asset.
|
||||
// writeDebugAsset write a debug entry for the given asset.
|
||||
// A debug entry is simply a function which reads the asset from
|
||||
// the original file (e.g.: from disk).
|
||||
func writeDebug(w io.Writer, c *Config, asset *Asset) {
|
||||
fmt.Fprintf(w, `func %s() []byte {
|
||||
func writeDebugAsset(w io.Writer, c *Config, asset *Asset) error {
|
||||
_, err := fmt.Fprintf(w, `func %s() []byte {
|
||||
return bindata_read(
|
||||
%q,
|
||||
%q,
|
||||
|
@ -66,4 +102,5 @@ func writeDebug(w io.Writer, c *Config, asset *Asset) {
|
|||
}
|
||||
|
||||
`, asset.Func, asset.Path, asset.Name)
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ func parseArgs() (*bindata.Config, bindata.ProgressFunc) {
|
|||
flag.StringVar(&c.Prefix, "prefix", c.Prefix, "Optional path prefix to strip off map keys and function names.")
|
||||
flag.StringVar(&c.Package, "pkg", c.Package, "Package name to use in the generated code.")
|
||||
flag.BoolVar(&c.NoMemCopy, "nomemcopy", c.NoMemCopy, "Use a .rodata hack to get rid of unnecessary memcopies. Refer to the documentation to see what implications this carries.")
|
||||
flag.BoolVar(&c.Compress, "compress", c.Compress, "Assets will be GZIP compressed when this flag is specified.")
|
||||
flag.BoolVar(&c.Compress, "nocompress", !c.Compress, "Assets will /not/ be GZIP compressed when this flag is specified.")
|
||||
flag.BoolVar(&version, "version", false, "Displays version information.")
|
||||
flag.BoolVar(&quiet, "quiet", false, "Do not print conversion status.")
|
||||
flag.Parse()
|
||||
|
@ -101,6 +101,9 @@ func parseArgs() (*bindata.Config, bindata.ProgressFunc) {
|
|||
}
|
||||
}
|
||||
|
||||
// The command line flag supplies the inversion of this value.
|
||||
c.Compress = !c.Compress
|
||||
|
||||
if quiet {
|
||||
return c, nil
|
||||
}
|
||||
|
|
143
release.go
143
release.go
|
@ -9,40 +9,74 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// writeRelease writes the release code file.
|
||||
func writeRelease(c *Config, toc []Asset) error {
|
||||
fd, err := os.Create(filepath.Join(c.Output, "bindata_release.go"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer fd.Close()
|
||||
|
||||
err = writeReleaseHeader(fd, c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for i := range toc {
|
||||
err = writeReleaseAsset(fd, c, &toc[i])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// writeReleaseHeader writes output file headers.
|
||||
// This targets release builds.
|
||||
func writeReleaseHeader(w io.Writer, c *Config) {
|
||||
func writeReleaseHeader(w io.Writer, c *Config) error {
|
||||
var err error
|
||||
|
||||
// Write build tags, if applicable.
|
||||
if len(c.Tags) > 0 {
|
||||
fmt.Fprintf(w, "// +build release %s\n\n", c.Tags)
|
||||
_, err = fmt.Fprintf(w, "// +build release %s\n\n", c.Tags)
|
||||
} else {
|
||||
fmt.Fprintf(w, "// +build release\n\n")
|
||||
_, err = fmt.Fprintf(w, "// +build release\n\n")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Write package declaration
|
||||
fmt.Fprintf(w, "package %s\n\n", c.Package)
|
||||
_, err = fmt.Fprintf(w, "package %s\n\n", c.Package)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if c.Compress {
|
||||
if c.NoMemCopy {
|
||||
header_compressed_nomemcopy(w)
|
||||
return header_compressed_nomemcopy(w)
|
||||
} else {
|
||||
header_compressed_memcopy(w)
|
||||
return header_compressed_memcopy(w)
|
||||
}
|
||||
} else {
|
||||
if c.NoMemCopy {
|
||||
header_uncompressed_nomemcopy(w)
|
||||
return header_uncompressed_nomemcopy(w)
|
||||
} else {
|
||||
header_uncompressed_memcopy(w)
|
||||
return header_uncompressed_memcopy(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// writeRelease write a release entry for the given asset.
|
||||
// writeReleaseAsset write a release entry for the given asset.
|
||||
// A release entry is a function which embeds and returns
|
||||
// the file's byte content.
|
||||
func writeRelease(w io.Writer, c *Config, asset *Asset) error {
|
||||
func writeReleaseAsset(w io.Writer, c *Config, asset *Asset) error {
|
||||
fd, err := os.Open(asset.Path)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -52,23 +86,23 @@ func writeRelease(w io.Writer, c *Config, asset *Asset) error {
|
|||
|
||||
if c.Compress {
|
||||
if c.NoMemCopy {
|
||||
compressed_nomemcopy(w, asset, fd)
|
||||
return compressed_nomemcopy(w, asset, fd)
|
||||
} else {
|
||||
compressed_memcopy(w, asset, fd)
|
||||
return compressed_memcopy(w, asset, fd)
|
||||
}
|
||||
} else {
|
||||
if c.NoMemCopy {
|
||||
uncompressed_nomemcopy(w, asset, fd)
|
||||
return uncompressed_nomemcopy(w, asset, fd)
|
||||
} else {
|
||||
uncompressed_memcopy(w, asset, fd)
|
||||
return uncompressed_memcopy(w, asset, fd)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func header_compressed_nomemcopy(w io.Writer) {
|
||||
fmt.Fprintf(w, `
|
||||
func header_compressed_nomemcopy(w io.Writer) error {
|
||||
_, err := fmt.Fprintf(w, `
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
|
@ -104,10 +138,11 @@ func bindata_read(data, name string) []byte {
|
|||
}
|
||||
|
||||
`)
|
||||
return err
|
||||
}
|
||||
|
||||
func header_compressed_memcopy(w io.Writer) {
|
||||
fmt.Fprintf(w, `
|
||||
func header_compressed_memcopy(w io.Writer) error {
|
||||
_, err := fmt.Fprintf(w, `
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
|
@ -133,10 +168,11 @@ func bindata_read(data []byte, name string) []byte {
|
|||
}
|
||||
|
||||
`)
|
||||
return err
|
||||
}
|
||||
|
||||
func header_uncompressed_nomemcopy(w io.Writer) {
|
||||
fmt.Fprintf(w, `
|
||||
func header_uncompressed_nomemcopy(w io.Writer) error {
|
||||
_, err := fmt.Fprintf(w, `
|
||||
import (
|
||||
"reflect"
|
||||
"unsafe"
|
||||
|
@ -154,20 +190,29 @@ func bindata_read(data, name string) []byte {
|
|||
}
|
||||
|
||||
`)
|
||||
return err
|
||||
}
|
||||
|
||||
func header_uncompressed_memcopy(w io.Writer) {
|
||||
func header_uncompressed_memcopy(w io.Writer) error {
|
||||
// nop -- We require no imports or helper functions.
|
||||
return nil
|
||||
}
|
||||
|
||||
func compressed_nomemcopy(w io.Writer, asset *Asset, r io.Reader) {
|
||||
fmt.Fprintf(w, `var _%s = "`, asset.Func)
|
||||
func compressed_nomemcopy(w io.Writer, asset *Asset, r io.Reader) error {
|
||||
_, err := fmt.Fprintf(w, `var _%s = "`, asset.Func)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
gz := gzip.NewWriter(&StringWriter{Writer: w})
|
||||
io.Copy(gz, r)
|
||||
_, err = io.Copy(gz, r)
|
||||
gz.Close()
|
||||
|
||||
fmt.Fprintf(w, `"
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = fmt.Fprintf(w, `"
|
||||
|
||||
func %s() []byte {
|
||||
return bindata_read(
|
||||
|
@ -177,31 +222,47 @@ func %s() []byte {
|
|||
}
|
||||
|
||||
`, asset.Func, asset.Func, asset.Name)
|
||||
return err
|
||||
}
|
||||
|
||||
func compressed_memcopy(w io.Writer, asset *Asset, r io.Reader) {
|
||||
fmt.Fprintf(w, `func %s() []byte {
|
||||
func compressed_memcopy(w io.Writer, asset *Asset, r io.Reader) error {
|
||||
_, err := fmt.Fprintf(w, `func %s() []byte {
|
||||
return bindata_read([]byte{`, asset.Func)
|
||||
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
gz := gzip.NewWriter(&ByteWriter{Writer: w})
|
||||
io.Copy(gz, r)
|
||||
_, err = io.Copy(gz, r)
|
||||
gz.Close()
|
||||
|
||||
fmt.Fprintf(w, `
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = fmt.Fprintf(w, `
|
||||
},
|
||||
%q,
|
||||
)
|
||||
}
|
||||
|
||||
`, asset.Name)
|
||||
return err
|
||||
}
|
||||
|
||||
func uncompressed_nomemcopy(w io.Writer, asset *Asset, r io.Reader) {
|
||||
fmt.Fprintf(w, `var _%s = "`, asset.Func)
|
||||
func uncompressed_nomemcopy(w io.Writer, asset *Asset, r io.Reader) error {
|
||||
_, err := fmt.Fprintf(w, `var _%s = "`, asset.Func)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
io.Copy(&StringWriter{Writer: w}, r)
|
||||
_, err = io.Copy(&StringWriter{Writer: w}, r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintf(w, `"
|
||||
_, err = fmt.Fprintf(w, `"
|
||||
|
||||
func %s() []byte {
|
||||
return bindata_read(
|
||||
|
@ -211,17 +272,25 @@ func %s() []byte {
|
|||
}
|
||||
|
||||
`, asset.Func, asset.Func, asset.Name)
|
||||
return err
|
||||
}
|
||||
|
||||
func uncompressed_memcopy(w io.Writer, asset *Asset, r io.Reader) {
|
||||
fmt.Fprintf(w, `func %s() []byte {
|
||||
func uncompressed_memcopy(w io.Writer, asset *Asset, r io.Reader) error {
|
||||
_, err := fmt.Fprintf(w, `func %s() []byte {
|
||||
return []byte{`, asset.Func)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
io.Copy(&ByteWriter{Writer: w}, r)
|
||||
_, err = io.Copy(&ByteWriter{Writer: w}, r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Fprintf(w, `
|
||||
_, err = fmt.Fprintf(w, `
|
||||
}
|
||||
}
|
||||
|
||||
`)
|
||||
return err
|
||||
}
|
||||
|
|
2
testdata/in/a/test.asset
vendored
2
testdata/in/a/test.asset
vendored
|
@ -1 +1 @@
|
|||
sample file
|
||||
// sample file
|
||||
|
|
18
testdata/out/compress-memcpy/bindata.go
vendored
Normal file
18
testdata/out/compress-memcpy/bindata.go
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
package main
|
||||
|
||||
// Asset loads and returns the asset for the given name.
|
||||
// This returns nil of the asset could not be found.
|
||||
func Asset(name string) []byte {
|
||||
if f, ok := _bindata[name]; ok {
|
||||
return f()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||
var _bindata = map[string]func() []byte{
|
||||
"in/b/test.asset": in_b_test_asset,
|
||||
"in/test.asset": in_test_asset,
|
||||
"in/a/test.asset": in_a_test_asset,
|
||||
"in/c/test.asset": in_c_test_asset,
|
||||
}
|
57
testdata/out/compress-memcpy/bindata_debug.go
vendored
Normal file
57
testdata/out/compress-memcpy/bindata_debug.go
vendored
Normal file
|
@ -0,0 +1,57 @@
|
|||
// +build !release
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
// bindata_read reads the given file from disk.
|
||||
// It panics if anything went wrong.
|
||||
func bindata_read(path, name string) []byte {
|
||||
fd, err := os.Open(path)
|
||||
if err != nil {
|
||||
log.Fatalf("Read %s: %v", name, err)
|
||||
}
|
||||
|
||||
defer fd.Close()
|
||||
|
||||
var buf bytes.Buffer
|
||||
_, err = io.Copy(&buf, fd)
|
||||
if err != nil {
|
||||
log.Fatalf("Read %s: %v", name, err)
|
||||
}
|
||||
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
func in_b_test_asset() []byte {
|
||||
return bindata_read(
|
||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/b/test.asset",
|
||||
"in/b/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
func in_test_asset() []byte {
|
||||
return bindata_read(
|
||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/test.asset",
|
||||
"in/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
func in_a_test_asset() []byte {
|
||||
return bindata_read(
|
||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/a/test.asset",
|
||||
"in/a/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
func in_c_test_asset() []byte {
|
||||
return bindata_read(
|
||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/c/test.asset",
|
||||
"in/c/test.asset",
|
||||
)
|
||||
}
|
71
testdata/out/compress-memcpy/bindata_release.go
vendored
Normal file
71
testdata/out/compress-memcpy/bindata_release.go
vendored
Normal file
|
@ -0,0 +1,71 @@
|
|||
// +build release
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"io"
|
||||
"log"
|
||||
)
|
||||
|
||||
func bindata_read(data []byte, name string) []byte {
|
||||
gz, err := gzip.NewReader(bytes.NewBuffer(data))
|
||||
if err != nil {
|
||||
log.Fatalf("Read %q: %v", name, err)
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
_, err = io.Copy(&buf, gz)
|
||||
gz.Close()
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("Read %q: %v", name, err)
|
||||
}
|
||||
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
func in_b_test_asset() []byte {
|
||||
return bindata_read([]byte{
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x00, 0xff, 0xd2, 0xd7,
|
||||
0x57, 0x28, 0x4e, 0xcc, 0x2d, 0xc8, 0x49, 0x55, 0x48, 0xcb, 0xcc, 0x49,
|
||||
0xe5, 0x02, 0x04, 0x00, 0x00, 0xff, 0xff, 0x8a, 0x82, 0x8c, 0x85, 0x0f,
|
||||
0x00, 0x00, 0x00,
|
||||
},
|
||||
"in/b/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
func in_test_asset() []byte {
|
||||
return bindata_read([]byte{
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x00, 0xff, 0xd2, 0xd7,
|
||||
0x57, 0x28, 0x4e, 0xcc, 0x2d, 0xc8, 0x49, 0x55, 0x48, 0xcb, 0xcc, 0x49,
|
||||
0xe5, 0x02, 0x04, 0x00, 0x00, 0xff, 0xff, 0x8a, 0x82, 0x8c, 0x85, 0x0f,
|
||||
0x00, 0x00, 0x00,
|
||||
},
|
||||
"in/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
func in_a_test_asset() []byte {
|
||||
return bindata_read([]byte{
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x00, 0xff, 0xd2, 0xd7,
|
||||
0x57, 0x28, 0x4e, 0xcc, 0x2d, 0xc8, 0x49, 0x55, 0x48, 0xcb, 0xcc, 0x49,
|
||||
0xe5, 0x02, 0x04, 0x00, 0x00, 0xff, 0xff, 0x8a, 0x82, 0x8c, 0x85, 0x0f,
|
||||
0x00, 0x00, 0x00,
|
||||
},
|
||||
"in/a/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
func in_c_test_asset() []byte {
|
||||
return bindata_read([]byte{
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x00, 0xff, 0xd2, 0xd7,
|
||||
0x57, 0x28, 0x4e, 0xcc, 0x2d, 0xc8, 0x49, 0x55, 0x48, 0xcb, 0xcc, 0x49,
|
||||
0xe5, 0x02, 0x04, 0x00, 0x00, 0xff, 0xff, 0x8a, 0x82, 0x8c, 0x85, 0x0f,
|
||||
0x00, 0x00, 0x00,
|
||||
},
|
||||
"in/c/test.asset",
|
||||
)
|
||||
}
|
18
testdata/out/compress-nomemcpy/bindata.go
vendored
Normal file
18
testdata/out/compress-nomemcpy/bindata.go
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
package main
|
||||
|
||||
// Asset loads and returns the asset for the given name.
|
||||
// This returns nil of the asset could not be found.
|
||||
func Asset(name string) []byte {
|
||||
if f, ok := _bindata[name]; ok {
|
||||
return f()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||
var _bindata = map[string]func() []byte{
|
||||
"in/b/test.asset": in_b_test_asset,
|
||||
"in/test.asset": in_test_asset,
|
||||
"in/a/test.asset": in_a_test_asset,
|
||||
"in/c/test.asset": in_c_test_asset,
|
||||
}
|
57
testdata/out/compress-nomemcpy/bindata_debug.go
vendored
Normal file
57
testdata/out/compress-nomemcpy/bindata_debug.go
vendored
Normal file
|
@ -0,0 +1,57 @@
|
|||
// +build !release
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
// bindata_read reads the given file from disk.
|
||||
// It panics if anything went wrong.
|
||||
func bindata_read(path, name string) []byte {
|
||||
fd, err := os.Open(path)
|
||||
if err != nil {
|
||||
log.Fatalf("Read %s: %v", name, err)
|
||||
}
|
||||
|
||||
defer fd.Close()
|
||||
|
||||
var buf bytes.Buffer
|
||||
_, err = io.Copy(&buf, fd)
|
||||
if err != nil {
|
||||
log.Fatalf("Read %s: %v", name, err)
|
||||
}
|
||||
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
func in_b_test_asset() []byte {
|
||||
return bindata_read(
|
||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/b/test.asset",
|
||||
"in/b/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
func in_test_asset() []byte {
|
||||
return bindata_read(
|
||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/test.asset",
|
||||
"in/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
func in_a_test_asset() []byte {
|
||||
return bindata_read(
|
||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/a/test.asset",
|
||||
"in/a/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
func in_c_test_asset() []byte {
|
||||
return bindata_read(
|
||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/c/test.asset",
|
||||
"in/c/test.asset",
|
||||
)
|
||||
}
|
73
testdata/out/compress-nomemcpy/bindata_release.go
vendored
Normal file
73
testdata/out/compress-nomemcpy/bindata_release.go
vendored
Normal file
|
@ -0,0 +1,73 @@
|
|||
// +build release
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"io"
|
||||
"log"
|
||||
"reflect"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func bindata_read(data, name string) []byte {
|
||||
var empty [0]byte
|
||||
sx := (*reflect.StringHeader)(unsafe.Pointer(&data))
|
||||
b := empty[:]
|
||||
bx := (*reflect.SliceHeader)(unsafe.Pointer(&b))
|
||||
bx.Data = sx.Data
|
||||
bx.Len = len(data)
|
||||
bx.Cap = bx.Len
|
||||
|
||||
gz, err := gzip.NewReader(bytes.NewBuffer(b))
|
||||
if err != nil {
|
||||
log.Fatalf("Read %q: %v", name, err)
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
_, err = io.Copy(&buf, gz)
|
||||
gz.Close()
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("Read %q: %v", name, err)
|
||||
}
|
||||
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
var _in_b_test_asset = "\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xd2\xd7\x57\x28\x4e\xcc\x2d\xc8\x49\x55\x48\xcb\xcc\x49\xe5\x02\x04\x00\x00\xff\xff\x8a\x82\x8c\x85\x0f\x00\x00\x00"
|
||||
|
||||
func in_b_test_asset() []byte {
|
||||
return bindata_read(
|
||||
_in_b_test_asset,
|
||||
"in/b/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
var _in_test_asset = "\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xd2\xd7\x57\x28\x4e\xcc\x2d\xc8\x49\x55\x48\xcb\xcc\x49\xe5\x02\x04\x00\x00\xff\xff\x8a\x82\x8c\x85\x0f\x00\x00\x00"
|
||||
|
||||
func in_test_asset() []byte {
|
||||
return bindata_read(
|
||||
_in_test_asset,
|
||||
"in/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
var _in_a_test_asset = "\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xd2\xd7\x57\x28\x4e\xcc\x2d\xc8\x49\x55\x48\xcb\xcc\x49\xe5\x02\x04\x00\x00\xff\xff\x8a\x82\x8c\x85\x0f\x00\x00\x00"
|
||||
|
||||
func in_a_test_asset() []byte {
|
||||
return bindata_read(
|
||||
_in_a_test_asset,
|
||||
"in/a/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
var _in_c_test_asset = "\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xd2\xd7\x57\x28\x4e\xcc\x2d\xc8\x49\x55\x48\xcb\xcc\x49\xe5\x02\x04\x00\x00\xff\xff\x8a\x82\x8c\x85\x0f\x00\x00\x00"
|
||||
|
||||
func in_c_test_asset() []byte {
|
||||
return bindata_read(
|
||||
_in_c_test_asset,
|
||||
"in/c/test.asset",
|
||||
)
|
||||
}
|
18
testdata/out/nocompress-memcpy/bindata.go
vendored
Normal file
18
testdata/out/nocompress-memcpy/bindata.go
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
package main
|
||||
|
||||
// Asset loads and returns the asset for the given name.
|
||||
// This returns nil of the asset could not be found.
|
||||
func Asset(name string) []byte {
|
||||
if f, ok := _bindata[name]; ok {
|
||||
return f()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||
var _bindata = map[string]func() []byte{
|
||||
"in/b/test.asset": in_b_test_asset,
|
||||
"in/test.asset": in_test_asset,
|
||||
"in/a/test.asset": in_a_test_asset,
|
||||
"in/c/test.asset": in_c_test_asset,
|
||||
}
|
57
testdata/out/nocompress-memcpy/bindata_debug.go
vendored
Normal file
57
testdata/out/nocompress-memcpy/bindata_debug.go
vendored
Normal file
|
@ -0,0 +1,57 @@
|
|||
// +build !release
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
// bindata_read reads the given file from disk.
|
||||
// It panics if anything went wrong.
|
||||
func bindata_read(path, name string) []byte {
|
||||
fd, err := os.Open(path)
|
||||
if err != nil {
|
||||
log.Fatalf("Read %s: %v", name, err)
|
||||
}
|
||||
|
||||
defer fd.Close()
|
||||
|
||||
var buf bytes.Buffer
|
||||
_, err = io.Copy(&buf, fd)
|
||||
if err != nil {
|
||||
log.Fatalf("Read %s: %v", name, err)
|
||||
}
|
||||
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
func in_b_test_asset() []byte {
|
||||
return bindata_read(
|
||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/b/test.asset",
|
||||
"in/b/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
func in_test_asset() []byte {
|
||||
return bindata_read(
|
||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/test.asset",
|
||||
"in/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
func in_a_test_asset() []byte {
|
||||
return bindata_read(
|
||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/a/test.asset",
|
||||
"in/a/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
func in_c_test_asset() []byte {
|
||||
return bindata_read(
|
||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/c/test.asset",
|
||||
"in/c/test.asset",
|
||||
)
|
||||
}
|
31
testdata/out/nocompress-memcpy/bindata_release.go
vendored
Normal file
31
testdata/out/nocompress-memcpy/bindata_release.go
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
// +build release
|
||||
|
||||
package main
|
||||
|
||||
func in_b_test_asset() []byte {
|
||||
return []byte{
|
||||
0x2f, 0x2f, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x66, 0x69,
|
||||
0x6c, 0x65, 0x0a,
|
||||
}
|
||||
}
|
||||
|
||||
func in_test_asset() []byte {
|
||||
return []byte{
|
||||
0x2f, 0x2f, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x66, 0x69,
|
||||
0x6c, 0x65, 0x0a,
|
||||
}
|
||||
}
|
||||
|
||||
func in_a_test_asset() []byte {
|
||||
return []byte{
|
||||
0x2f, 0x2f, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x66, 0x69,
|
||||
0x6c, 0x65, 0x0a,
|
||||
}
|
||||
}
|
||||
|
||||
func in_c_test_asset() []byte {
|
||||
return []byte{
|
||||
0x2f, 0x2f, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x66, 0x69,
|
||||
0x6c, 0x65, 0x0a,
|
||||
}
|
||||
}
|
18
testdata/out/nocompress-nomemcpy/bindata.go
vendored
Normal file
18
testdata/out/nocompress-nomemcpy/bindata.go
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
package main
|
||||
|
||||
// Asset loads and returns the asset for the given name.
|
||||
// This returns nil of the asset could not be found.
|
||||
func Asset(name string) []byte {
|
||||
if f, ok := _bindata[name]; ok {
|
||||
return f()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||
var _bindata = map[string]func() []byte{
|
||||
"in/b/test.asset": in_b_test_asset,
|
||||
"in/test.asset": in_test_asset,
|
||||
"in/a/test.asset": in_a_test_asset,
|
||||
"in/c/test.asset": in_c_test_asset,
|
||||
}
|
57
testdata/out/nocompress-nomemcpy/bindata_debug.go
vendored
Normal file
57
testdata/out/nocompress-nomemcpy/bindata_debug.go
vendored
Normal file
|
@ -0,0 +1,57 @@
|
|||
// +build !release
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
// bindata_read reads the given file from disk.
|
||||
// It panics if anything went wrong.
|
||||
func bindata_read(path, name string) []byte {
|
||||
fd, err := os.Open(path)
|
||||
if err != nil {
|
||||
log.Fatalf("Read %s: %v", name, err)
|
||||
}
|
||||
|
||||
defer fd.Close()
|
||||
|
||||
var buf bytes.Buffer
|
||||
_, err = io.Copy(&buf, fd)
|
||||
if err != nil {
|
||||
log.Fatalf("Read %s: %v", name, err)
|
||||
}
|
||||
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
func in_b_test_asset() []byte {
|
||||
return bindata_read(
|
||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/b/test.asset",
|
||||
"in/b/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
func in_test_asset() []byte {
|
||||
return bindata_read(
|
||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/test.asset",
|
||||
"in/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
func in_a_test_asset() []byte {
|
||||
return bindata_read(
|
||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/a/test.asset",
|
||||
"in/a/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
func in_c_test_asset() []byte {
|
||||
return bindata_read(
|
||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/c/test.asset",
|
||||
"in/c/test.asset",
|
||||
)
|
||||
}
|
55
testdata/out/nocompress-nomemcpy/bindata_release.go
vendored
Normal file
55
testdata/out/nocompress-nomemcpy/bindata_release.go
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
// +build release
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func bindata_read(data, name string) []byte {
|
||||
var empty [0]byte
|
||||
sx := (*reflect.StringHeader)(unsafe.Pointer(&data))
|
||||
b := empty[:]
|
||||
bx := (*reflect.SliceHeader)(unsafe.Pointer(&b))
|
||||
bx.Data = sx.Data
|
||||
bx.Len = len(data)
|
||||
bx.Cap = bx.Len
|
||||
return b
|
||||
}
|
||||
|
||||
var _in_b_test_asset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a"
|
||||
|
||||
func in_b_test_asset() []byte {
|
||||
return bindata_read(
|
||||
_in_b_test_asset,
|
||||
"in/b/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
var _in_test_asset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a"
|
||||
|
||||
func in_test_asset() []byte {
|
||||
return bindata_read(
|
||||
_in_test_asset,
|
||||
"in/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
var _in_a_test_asset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a"
|
||||
|
||||
func in_a_test_asset() []byte {
|
||||
return bindata_read(
|
||||
_in_a_test_asset,
|
||||
"in/a/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
var _in_c_test_asset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a"
|
||||
|
||||
func in_c_test_asset() []byte {
|
||||
return bindata_read(
|
||||
_in_c_test_asset,
|
||||
"in/c/test.asset",
|
||||
)
|
||||
}
|
69
toc.go
Normal file
69
toc.go
Normal file
|
@ -0,0 +1,69 @@
|
|||
// This work is subject to the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
|
||||
// license. Its contents can be found at:
|
||||
// http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
package bindata
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// writeTOC writes the table of contents file.
|
||||
func writeTOC(c *Config, toc []Asset) error {
|
||||
fd, err := os.Create(filepath.Join(c.Output, "bindata.go"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer fd.Close()
|
||||
|
||||
err = writeTOCHeader(fd, c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for i := range toc {
|
||||
err = writeTOCAsset(fd, c, &toc[i])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return writeTOCFooter(fd, c)
|
||||
}
|
||||
|
||||
// writeTOCHeader writes the table of contents file header.
|
||||
func writeTOCHeader(w io.Writer, c *Config) error {
|
||||
_, err := fmt.Fprintf(w, `package %s
|
||||
|
||||
// Asset loads and returns the asset for the given name.
|
||||
// This returns nil of the asset could not be found.
|
||||
func Asset(name string) []byte {
|
||||
if f, ok := _bindata[name]; ok {
|
||||
return f()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||
var _bindata = map[string] func() []byte {
|
||||
`, c.Package)
|
||||
return err
|
||||
}
|
||||
|
||||
// writeTOCAsset write a TOC entry for the given asset.
|
||||
func writeTOCAsset(w io.Writer, c *Config, asset *Asset) error {
|
||||
_, err := fmt.Fprintf(w, "\t%q: %s,\n", asset.Name, asset.Func)
|
||||
return err
|
||||
}
|
||||
|
||||
// writeTOCFooter writes the table of contents file footer.
|
||||
func writeTOCFooter(w io.Writer, c *Config) error {
|
||||
_, err := fmt.Fprintf(w, `
|
||||
}
|
||||
`)
|
||||
return err
|
||||
}
|
Loading…
Reference in New Issue
Block a user