Compare commits

..

No commits in common. "master" and "v3.0.5" have entirely different histories.

29 changed files with 342 additions and 2386 deletions

View File

@ -70,7 +70,7 @@ good to keep in mind:
> the rest of the API. This addresses issue #32 > the rest of the API. This addresses issue #32
Do not pile a lot of unrelated changes into a single commit. Do not pile a lot of unrelated changes into a single commit.
Pick and choose only those changes for a single commit, which are Pick and chose only those changes for a single commit, which are
directly related. We would much rather see a hundred commits directly related. We would much rather see a hundred commits
saying nothing but `"Runs go fmt"` in between any real fixes saying nothing but `"Runs go fmt"` in between any real fixes
than have these style changes embedded in those real fixes. than have these style changes embedded in those real fixes.

View File

@ -1,2 +0,0 @@
all:
make -C testdata

View File

@ -1,13 +1,3 @@
> **NOTICE:**
>
> This repository is a fork of <https://github.com/jteeuwen/go-bindata> which
> itself was a fork of an original project that disappeared.
>
> I've cloned a copy for personal use at <https://git.kirsle.net/go/bindata> so
> that I always have a version that won't disappear.
>
> [@kirsle](https://www.kirsle.net/)
## bindata ## bindata
This package converts any file into managable Go source code. Useful for This package converts any file into managable Go source code. Useful for
@ -23,7 +13,7 @@ output being generated.
To install the library and command line program, use the following: To install the library and command line program, use the following:
go get -u git.kirsle.net/go/bindata/... go get github.com/jteeuwen/go-bindata/...
### Usage ### Usage
@ -52,22 +42,19 @@ Multiple input directories can be specified if necessary.
$ go-bindata dir1/... /path/to/dir2/... dir3 $ go-bindata dir1/... /path/to/dir2/... dir3
The following paragraphs detail some of the command line options which can be The following paragraphs detail some of the command line options which can
supplied to `go-bindata`. Refer to the `testdata/out` directory for various supplied to `go-bindata`. Refer to the `testdata/out` directory for various
output examples from the assets in `testdata/in`. Each example uses different output examples from the assets in `testdata/in`. Each example uses different
command line options. command line options.
To ignore files, pass in regexes using -ignore, for example:
$ go-bindata -ignore=\\.gitignore data/...
### Accessing an asset ### Accessing an asset
To access asset data, we use the `Asset(string) ([]byte, error)` function which To access asset data, we use the `Asset(string) []byte` function which
is included in the generated output. is included in the generated output.
data, err := Asset("pub/style/foo.css") data := Asset("pub/style/foo.css")
if err != nil { if len(data) == 0 {
// Asset was not found. // Asset was not found.
} }
@ -192,7 +179,4 @@ format is specified at build time with the appropriate tags.
The tags are appended to a `// +build` line in the beginning of the output file The tags are appended to a `// +build` line in the beginning of the output file
and must follow the build tags syntax specified by the go tool. and must follow the build tags syntax specified by the go tool.
### Related projects
[go-bindata-assetfs](https://github.com/elazarl/go-bindata-assetfs#readme) -
implements `http.FileSystem` interface. Allows you to serve assets with `net/http`.

View File

@ -8,7 +8,6 @@ import (
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
"regexp"
) )
// InputConfig defines options on a asset directory to be convert. // InputConfig defines options on a asset directory to be convert.
@ -117,29 +116,10 @@ type Config struct {
// in the code. The default behaviour is Release mode. // in the code. The default behaviour is Release mode.
Debug bool Debug bool
// Perform a dev build, which is nearly identical to the debug option. The // Recursively process all assets in the input directory and its
// only difference is that instead of absolute file paths in generated code, // sub directories. This defaults to false, so only files in the
// it expects a variable, `rootDir`, to be set in the generated code's // input directory itself are read.
// package (the author needs to do this manually), which it then prepends to Recursive bool
// an asset's name to construct the file path on disk.
//
// This is mainly so you can push the generated code file to a shared
// repository.
Dev bool
// When true, size, mode and modtime are not preserved from files
NoMetadata bool
// When nonzero, use this as mode for all files.
Mode uint
// When nonzero, use this as unix timestamp for all files.
ModTime int64
// Ignores any filenames matching the regex pattern specified, e.g.
// path/to/file.ext will ignore only that file, or \\.gitignore
// will match any .gitignore file.
//
// This parameter can be provided multiple times.
Ignore []*regexp.Regexp
} }
// NewConfig returns a default configuration struct. // NewConfig returns a default configuration struct.
@ -149,8 +129,8 @@ func NewConfig() *Config {
c.NoMemCopy = false c.NoMemCopy = false
c.NoCompress = false c.NoCompress = false
c.Debug = false c.Debug = false
c.Recursive = false
c.Output = "./bindata.go" c.Output = "./bindata.go"
c.Ignore = make([]*regexp.Regexp, 0)
return c return c
} }
@ -162,10 +142,14 @@ func (c *Config) validate() error {
} }
for _, input := range c.Input { for _, input := range c.Input {
_, err := os.Lstat(input.Path) stat, err := os.Lstat(input.Path)
if err != nil { if err != nil {
return fmt.Errorf("Failed to stat input path '%s': %v", input.Path, err) return fmt.Errorf("Failed to stat input path '%s': %v", input.Path, err)
} }
if !stat.IsDir() {
return fmt.Errorf("Input path '%s' is not a directory.", input.Path)
}
} }
if len(c.Output) == 0 { if len(c.Output) == 0 {
@ -186,14 +170,12 @@ func (c *Config) validate() error {
// File does not exist. This is fine, just make // File does not exist. This is fine, just make
// sure the directory it is to be in exists. // sure the directory it is to be in exists.
dir, _ := filepath.Split(c.Output) dir, _ := filepath.Split(c.Output)
if dir != "" {
err = os.MkdirAll(dir, 0744) err = os.MkdirAll(dir, 0744)
if err != nil { if err != nil {
return fmt.Errorf("Create output directory: %v", err) return fmt.Errorf("Create output directory: %v", err)
} }
} }
}
if stat != nil && stat.IsDir() { if stat != nil && stat.IsDir() {
return fmt.Errorf("Output path is a directory.") return fmt.Errorf("Output path is a directory.")

View File

@ -10,7 +10,6 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"regexp" "regexp"
"sort"
"strings" "strings"
"unicode" "unicode"
) )
@ -27,11 +26,9 @@ func Translate(c *Config) error {
return err return err
} }
var knownFuncs = make(map[string]int)
var visitedPaths = make(map[string]bool)
// Locate all the assets. // Locate all the assets.
for _, input := range c.Input { for _, input := range c.Input {
err = findFiles(input.Path, c.Prefix, input.Recursive, &toc, c.Ignore, knownFuncs, visitedPaths) err = findFiles(input.Path, c.Prefix, input.Recursive, &toc)
if err != nil { if err != nil {
return err return err
} }
@ -49,32 +46,10 @@ func Translate(c *Config) error {
bfd := bufio.NewWriter(fd) bfd := bufio.NewWriter(fd)
defer bfd.Flush() defer bfd.Flush()
// Write the header. This makes e.g. Github ignore diffs in generated files.
if _, err = fmt.Fprint(bfd, "// Code generated by go-bindata.\n"); err != nil {
return err
}
if _, err = fmt.Fprint(bfd, "// sources:\n"); err != nil {
return err
}
wd, err := os.Getwd()
if err != nil {
return err
}
for _, asset := range toc {
relative, _ := filepath.Rel(wd, asset.Path)
if _, err = fmt.Fprintf(bfd, "// %s\n", filepath.ToSlash(relative)); err != nil {
return err
}
}
if _, err = fmt.Fprint(bfd, "// DO NOT EDIT!\n\n"); err != nil {
return err
}
// Write build tags, if applicable. // Write build tags, if applicable.
if len(c.Tags) > 0 { if len(c.Tags) > 0 {
if _, err = fmt.Fprintf(bfd, "// +build %s\n\n", c.Tags); err != nil { _, err = fmt.Fprintf(bfd, "// +build %s\n\n", c.Tags)
if err != nil {
return err return err
} }
} }
@ -86,8 +61,8 @@ func Translate(c *Config) error {
} }
// Write assets. // Write assets.
if c.Debug || c.Dev { if c.Debug {
err = writeDebug(bfd, c, toc) err = writeDebug(bfd, toc)
} else { } else {
err = writeRelease(bfd, c, toc) err = writeRelease(bfd, c, toc)
} }
@ -97,108 +72,44 @@ func Translate(c *Config) error {
} }
// Write table of contents // Write table of contents
if err := writeTOC(bfd, toc); err != nil { return writeTOC(bfd, toc)
return err
} }
// Write hierarchical tree of assets
if err := writeTOCTree(bfd, toc); err != nil {
return err
}
// Write restore procedure
return writeRestore(bfd)
}
// Implement sort.Interface for []os.FileInfo based on Name()
type ByName []os.FileInfo
func (v ByName) Len() int { return len(v) }
func (v ByName) Swap(i, j int) { v[i], v[j] = v[j], v[i] }
func (v ByName) Less(i, j int) bool { return v[i].Name() < v[j].Name() }
// findFiles recursively finds all the file paths in the given directory tree. // findFiles recursively finds all the file paths in the given directory tree.
// They are added to the given map as keys. Values will be safe function names // They are added to the given map as keys. Values will be safe function names
// for each file, which will be used when generating the output code. // for each file, which will be used when generating the output code.
func findFiles(dir, prefix string, recursive bool, toc *[]Asset, ignore []*regexp.Regexp, knownFuncs map[string]int, visitedPaths map[string]bool) error { func findFiles(dir, prefix string, recursive bool, toc *[]Asset) error {
dirpath := dir
if len(prefix) > 0 { if len(prefix) > 0 {
dirpath, _ = filepath.Abs(dirpath) dir, _ = filepath.Abs(dir)
prefix, _ = filepath.Abs(prefix) prefix, _ = filepath.Abs(prefix)
prefix = filepath.ToSlash(prefix)
} }
fi, err := os.Stat(dirpath) fd, err := os.Open(dir)
if err != nil {
return err
}
var list []os.FileInfo
if !fi.IsDir() {
dirpath = filepath.Dir(dirpath)
list = []os.FileInfo{fi}
} else {
visitedPaths[dirpath] = true
fd, err := os.Open(dirpath)
if err != nil { if err != nil {
return err return err
} }
defer fd.Close() defer fd.Close()
list, err = fd.Readdir(0) list, err := fd.Readdir(0)
if err != nil { if err != nil {
return err return err
} }
// Sort to make output stable between invocations
sort.Sort(ByName(list))
}
for _, file := range list { for _, file := range list {
var asset Asset var asset Asset
asset.Path = filepath.Join(dirpath, file.Name()) asset.Path = filepath.Join(dir, file.Name())
asset.Name = filepath.ToSlash(asset.Path) asset.Name = asset.Path
ignoring := false
for _, re := range ignore {
if re.MatchString(asset.Path) {
ignoring = true
break
}
}
if ignoring {
continue
}
if file.IsDir() { if file.IsDir() {
if recursive { if recursive {
recursivePath := filepath.Join(dir, file.Name()) findFiles(asset.Path, prefix, recursive, toc)
visitedPaths[asset.Path] = true
findFiles(recursivePath, prefix, recursive, toc, ignore, knownFuncs, visitedPaths)
}
continue
} else if file.Mode()&os.ModeSymlink == os.ModeSymlink {
var linkPath string
if linkPath, err = os.Readlink(asset.Path); err != nil {
return err
}
if !filepath.IsAbs(linkPath) {
if linkPath, err = filepath.Abs(dirpath + "/" + linkPath); err != nil {
return err
}
}
if _, ok := visitedPaths[linkPath]; !ok {
visitedPaths[linkPath] = true
findFiles(asset.Path, prefix, recursive, toc, ignore, knownFuncs, visitedPaths)
} }
continue continue
} }
if strings.HasPrefix(asset.Name, prefix) { if strings.HasPrefix(asset.Name, prefix) {
asset.Name = asset.Name[len(prefix):] asset.Name = asset.Name[len(prefix):]
} else {
asset.Name = filepath.Join(dir, file.Name())
} }
// If we have a leading slash, get rid of it. // If we have a leading slash, get rid of it.
@ -211,7 +122,7 @@ func findFiles(dir, prefix string, recursive bool, toc *[]Asset, ignore []*regex
return fmt.Errorf("Invalid file: %v", asset.Path) return fmt.Errorf("Invalid file: %v", asset.Path)
} }
asset.Func = safeFunctionName(asset.Name, knownFuncs) asset.Func = safeFunctionName(asset.Name)
asset.Path, _ = filepath.Abs(asset.Path) asset.Path, _ = filepath.Abs(asset.Path)
*toc = append(*toc, asset) *toc = append(*toc, asset)
} }
@ -222,40 +133,25 @@ func findFiles(dir, prefix string, recursive bool, toc *[]Asset, ignore []*regex
var regFuncName = regexp.MustCompile(`[^a-zA-Z0-9_]`) var regFuncName = regexp.MustCompile(`[^a-zA-Z0-9_]`)
// safeFunctionName converts the given name into a name // safeFunctionName converts the given name into a name
// which qualifies as a valid function identifier. It // which qualifies as a valid function identifier.
// also compares against a known list of functions to func safeFunctionName(name string) string {
// prevent conflict based on name translation.
func safeFunctionName(name string, knownFuncs map[string]int) string {
var inBytes, outBytes []byte
var toUpper bool
name = strings.ToLower(name) name = strings.ToLower(name)
inBytes = []byte(name) name = regFuncName.ReplaceAllString(name, "_")
for i := 0; i < len(inBytes); i++ { // Get rid of "__" instances for niceness.
if regFuncName.Match([]byte{inBytes[i]}) { for strings.Index(name, "__") > -1 {
toUpper = true name = strings.Replace(name, "__", "_", -1)
} else if toUpper {
outBytes = append(outBytes, []byte(strings.ToUpper(string(inBytes[i])))...)
toUpper = false
} else {
outBytes = append(outBytes, inBytes[i])
}
} }
name = string(outBytes) // Leading underscores are silly (unless they prefix a digit (see below)).
for len(name) > 1 && name[0] == '_' {
name = name[1:]
}
// Identifier can't start with a digit. // Identifier can't start with a digit.
if unicode.IsDigit(rune(name[0])) { if unicode.IsDigit(rune(name[0])) {
name = "_" + name name = "_" + name
} }
if num, ok := knownFuncs[name]; ok {
knownFuncs[name] = num + 1
name = fmt.Sprintf("%s%d", name, num)
} else {
knownFuncs[name] = 2
}
return name return name
} }

View File

@ -1,90 +0,0 @@
package bindata
import (
"regexp"
"strings"
"testing"
)
func TestSafeFunctionName(t *testing.T) {
var knownFuncs = make(map[string]int)
name1 := safeFunctionName("foo/bar", knownFuncs)
name2 := safeFunctionName("foo_bar", knownFuncs)
if name1 == name2 {
t.Errorf("name collision")
}
}
func TestFindFiles(t *testing.T) {
var toc []Asset
var knownFuncs = make(map[string]int)
var visitedPaths = make(map[string]bool)
err := findFiles("testdata/dupname", "testdata/dupname", true, &toc, []*regexp.Regexp{}, knownFuncs, visitedPaths)
if err != nil {
t.Errorf("expected to be no error: %+v", err)
}
if toc[0].Func == toc[1].Func {
t.Errorf("name collision")
}
}
func TestFindFilesWithSymlinks(t *testing.T) {
var tocSrc []Asset
var tocTarget []Asset
var knownFuncs = make(map[string]int)
var visitedPaths = make(map[string]bool)
err := findFiles("testdata/symlinkSrc", "testdata/symlinkSrc", true, &tocSrc, []*regexp.Regexp{}, knownFuncs, visitedPaths)
if err != nil {
t.Errorf("expected to be no error: %+v", err)
}
knownFuncs = make(map[string]int)
visitedPaths = make(map[string]bool)
err = findFiles("testdata/symlinkParent", "testdata/symlinkParent", true, &tocTarget, []*regexp.Regexp{}, knownFuncs, visitedPaths)
if err != nil {
t.Errorf("expected to be no error: %+v", err)
}
if len(tocSrc) != len(tocTarget) {
t.Errorf("Symlink source and target should have the same number of assets. Expected %d got %d", len(tocTarget), len(tocSrc))
} else {
for i, _ := range tocSrc {
targetFunc := strings.TrimPrefix(tocTarget[i].Func, "symlinktarget")
targetFunc = strings.ToLower(targetFunc[:1]) + targetFunc[1:]
if tocSrc[i].Func != targetFunc {
t.Errorf("Symlink source and target produced different function lists. Expected %s to be %s", targetFunc, tocSrc[i].Func)
}
}
}
}
func TestFindFilesWithRecursiveSymlinks(t *testing.T) {
var toc []Asset
var knownFuncs = make(map[string]int)
var visitedPaths = make(map[string]bool)
err := findFiles("testdata/symlinkRecursiveParent", "testdata/symlinkRecursiveParent", true, &toc, []*regexp.Regexp{}, knownFuncs, visitedPaths)
if err != nil {
t.Errorf("expected to be no error: %+v", err)
}
if len(toc) != 1 {
t.Errorf("Only one asset should have been found. Got %d: %v", len(toc), toc)
}
}
func TestFindFilesWithSymlinkedFile(t *testing.T) {
var toc []Asset
var knownFuncs = make(map[string]int)
var visitedPaths = make(map[string]bool)
err := findFiles("testdata/symlinkFile", "testdata/symlinkFile", true, &toc, []*regexp.Regexp{}, knownFuncs, visitedPaths)
if err != nil {
t.Errorf("expected to be no error: %+v", err)
}
if len(toc) != 1 {
t.Errorf("Only one asset should have been found. Got %d: %v", len(toc), toc)
}
}

View File

@ -10,14 +10,14 @@ import (
) )
// writeDebug writes the debug code file. // writeDebug writes the debug code file.
func writeDebug(w io.Writer, c *Config, toc []Asset) error { func writeDebug(w io.Writer, toc []Asset) error {
err := writeDebugHeader(w) err := writeDebugHeader(w)
if err != nil { if err != nil {
return err return err
} }
for i := range toc { for i := range toc {
err = writeDebugAsset(w, c, &toc[i]) err = writeDebugAsset(w, &toc[i])
if err != nil { if err != nil {
return err return err
} }
@ -32,13 +32,11 @@ func writeDebugHeader(w io.Writer) error {
_, err := fmt.Fprintf(w, `import ( _, err := fmt.Fprintf(w, `import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os"
"path/filepath"
"strings"
) )
// bindataRead reads the given file from disk. It returns an error on failure. // bindata_read reads the given file from disk. It returns
func bindataRead(path, name string) ([]byte, error) { // an error on failure.
func bindata_read(path, name string) ([]byte, error) {
buf, err := ioutil.ReadFile(path) buf, err := ioutil.ReadFile(path)
if err != nil { if err != nil {
err = fmt.Errorf("Error reading asset %%s at %%s: %%v", name, path, err) err = fmt.Errorf("Error reading asset %%s at %%s: %%v", name, path, err)
@ -46,11 +44,6 @@ func bindataRead(path, name string) ([]byte, error) {
return buf, err return buf, err
} }
type asset struct {
bytes []byte
info os.FileInfo
}
`) `)
return err return err
} }
@ -58,30 +51,16 @@ type asset struct {
// writeDebugAsset 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 // A debug entry is simply a function which reads the asset from
// the original file (e.g.: from disk). // the original file (e.g.: from disk).
func writeDebugAsset(w io.Writer, c *Config, asset *Asset) error { func writeDebugAsset(w io.Writer, asset *Asset) error {
pathExpr := fmt.Sprintf("%q", asset.Path) _, err := fmt.Fprintf(w, `
if c.Dev { // %s reads file data from disk.
pathExpr = fmt.Sprintf("filepath.Join(rootDir, %q)", asset.Name) // It panics if something went wrong in the process.
func %s() ([]byte, error) {
return bindata_read(
%q,
%q,
)
} }
`, asset.Func, asset.Func, asset.Path, asset.Name)
_, err := fmt.Fprintf(w, `// %s reads file data from disk. It returns an error on failure.
func %s() (*asset, error) {
path := %s
name := %q
bytes, err := bindataRead(path, name)
if err != nil {
return nil, err
}
fi, err := os.Stat(path)
if err != nil {
err = fmt.Errorf("Error reading asset info %%s at %%s: %%v", name, path, err)
}
a := &asset{bytes: bytes, info: fi}
return a, err
}
`, asset.Func, asset.Func, pathExpr, asset.Name)
return err return err
} }

View File

@ -1,22 +0,0 @@
package main
import "strings"
// borrowed from https://github.com/hashicorp/serf/blob/master/command/agent/flag_slice_value.go
// AppendSliceValue implements the flag.Value interface and allows multiple
// calls to the same variable to append a list.
type AppendSliceValue []string
func (s *AppendSliceValue) String() string {
return strings.Join(*s, ",")
}
func (s *AppendSliceValue) Set(value string) error {
if *s == nil {
*s = make([]string, 0, 1)
}
*s = append(*s, value)
return nil
}

View File

@ -7,12 +7,10 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"github.com/jteeuwen/go-bindata"
"os" "os"
"path/filepath" "path/filepath"
"regexp"
"strings" "strings"
"git.kirsle.net/go/bindata"
) )
func main() { func main() {
@ -41,29 +39,15 @@ func parseArgs() *bindata.Config {
} }
flag.BoolVar(&c.Debug, "debug", c.Debug, "Do not embed the assets, but provide the embedding API. Contents will still be loaded from disk.") flag.BoolVar(&c.Debug, "debug", c.Debug, "Do not embed the assets, but provide the embedding API. Contents will still be loaded from disk.")
flag.BoolVar(&c.Dev, "dev", c.Dev, "Similar to debug, but does not emit absolute paths. Expects a rootDir variable to already exist in the generated code's package.") flag.StringVar(&c.Tags, "tags", c.Tags, "Optional set of uild tags to include.")
flag.StringVar(&c.Tags, "tags", c.Tags, "Optional set of build tags to include.")
flag.StringVar(&c.Prefix, "prefix", c.Prefix, "Optional path prefix to strip off asset names.") flag.StringVar(&c.Prefix, "prefix", c.Prefix, "Optional path prefix to strip off asset names.")
flag.StringVar(&c.Package, "pkg", c.Package, "Package name to use in the generated code.") 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.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.NoCompress, "nocompress", c.NoCompress, "Assets will *not* be GZIP compressed when this flag is specified.") flag.BoolVar(&c.NoCompress, "nocompress", c.NoCompress, "Assets will *not* be GZIP compressed when this flag is specified.")
flag.BoolVar(&c.NoMetadata, "nometadata", c.NoMetadata, "Assets will not preserve size, mode, and modtime info.")
flag.UintVar(&c.Mode, "mode", c.Mode, "Optional file mode override for all files.")
flag.Int64Var(&c.ModTime, "modtime", c.ModTime, "Optional modification unix timestamp override for all files.")
flag.StringVar(&c.Output, "o", c.Output, "Optional name of the output file to be generated.") flag.StringVar(&c.Output, "o", c.Output, "Optional name of the output file to be generated.")
flag.BoolVar(&version, "version", false, "Displays version information.") flag.BoolVar(&version, "version", false, "Displays version information.")
ignore := make([]string, 0)
flag.Var((*AppendSliceValue)(&ignore), "ignore", "Regex pattern to ignore")
flag.Parse() flag.Parse()
patterns := make([]*regexp.Regexp, 0)
for _, pattern := range ignore {
patterns = append(patterns, regexp.MustCompile(pattern))
}
c.Ignore = patterns
if version { if version {
fmt.Printf("%s\n", Version()) fmt.Printf("%s\n", Version())
os.Exit(0) os.Exit(0)

View File

@ -5,13 +5,10 @@
package bindata package bindata
import ( import (
"bytes"
"compress/gzip" "compress/gzip"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os" "os"
"unicode/utf8"
) )
// writeRelease writes the release code file. // writeRelease writes the release code file.
@ -34,24 +31,19 @@ func writeRelease(w io.Writer, c *Config, toc []Asset) error {
// writeReleaseHeader writes output file headers. // writeReleaseHeader writes output file headers.
// This targets release builds. // This targets release builds.
func writeReleaseHeader(w io.Writer, c *Config) error { func writeReleaseHeader(w io.Writer, c *Config) error {
var err error
if c.NoCompress { if c.NoCompress {
if c.NoMemCopy { if c.NoMemCopy {
err = header_uncompressed_nomemcopy(w) return header_uncompressed_nomemcopy(w)
} else { } else {
err = header_uncompressed_memcopy(w) return header_uncompressed_memcopy(w)
} }
} else { } else {
if c.NoMemCopy { if c.NoMemCopy {
err = header_compressed_nomemcopy(w) return header_compressed_nomemcopy(w)
} else { } else {
err = header_compressed_memcopy(w) return header_compressed_memcopy(w)
} }
} }
if err != nil {
return err
}
return header_release_common(w)
} }
// writeReleaseAsset write a release entry for the given asset. // writeReleaseAsset write a release entry for the given asset.
@ -67,34 +59,19 @@ func writeReleaseAsset(w io.Writer, c *Config, asset *Asset) error {
if c.NoCompress { if c.NoCompress {
if c.NoMemCopy { if c.NoMemCopy {
err = uncompressed_nomemcopy(w, asset, fd) return uncompressed_nomemcopy(w, asset, fd)
} else { } else {
err = uncompressed_memcopy(w, asset, fd) return uncompressed_memcopy(w, asset, fd)
} }
} else { } else {
if c.NoMemCopy { if c.NoMemCopy {
err = compressed_nomemcopy(w, asset, fd) return compressed_nomemcopy(w, asset, fd)
} else { } else {
err = compressed_memcopy(w, asset, fd) return compressed_memcopy(w, asset, fd)
} }
} }
if err != nil {
return err
}
return asset_release_common(w, c, asset)
}
// sanitize prepares a valid UTF-8 string as a raw string constant. return nil
// Based on https://code.google.com/p/go/source/browse/godoc/static/makestatic.go?repo=tools
func sanitize(b []byte) []byte {
// Replace ` with `+"`"+`
b = bytes.Replace(b, []byte("`"), []byte("`+\"`\"+`"), -1)
// Replace BOM with `+"\xEF\xBB\xBF"+`
// (A BOM is valid UTF-8 but not permitted in Go source files.
// I wouldn't bother handling this, but for some insane reason
// jquery.js has a BOM somewhere in the middle.)
return bytes.Replace(b, []byte("\xEF\xBB\xBF"), []byte("`+\"\\xEF\\xBB\\xBF\"+`"), -1)
} }
func header_compressed_nomemcopy(w io.Writer) error { func header_compressed_nomemcopy(w io.Writer) error {
@ -103,29 +80,31 @@ func header_compressed_nomemcopy(w io.Writer) error {
"compress/gzip" "compress/gzip"
"fmt" "fmt"
"io" "io"
"io/ioutil" "reflect"
"os" "unsafe"
"path/filepath"
"strings"
"time"
) )
func bindataRead(data, name string) ([]byte, error) { func bindata_read(data, name string) ([]byte, error) {
gz, err := gzip.NewReader(strings.NewReader(data)) 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 { if err != nil {
return nil, fmt.Errorf("Read %%q: %%v", name, err) return nil, fmt.Errorf("Read %%q: %%v", name, err)
} }
var buf bytes.Buffer var buf bytes.Buffer
_, err = io.Copy(&buf, gz) _, err = io.Copy(&buf, gz)
clErr := gz.Close() gz.Close()
if err != nil { if err != nil {
return nil, fmt.Errorf("Read %%q: %%v", name, err) return nil, fmt.Errorf("Read %%q: %%v", name, err)
} }
if clErr != nil {
return nil, err
}
return buf.Bytes(), nil return buf.Bytes(), nil
} }
@ -140,14 +119,9 @@ func header_compressed_memcopy(w io.Writer) error {
"compress/gzip" "compress/gzip"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"os"
"path/filepath"
"strings"
"time"
) )
func bindataRead(data []byte, name string) ([]byte, error) { func bindata_read(data []byte, name string) ([]byte, error) {
gz, err := gzip.NewReader(bytes.NewBuffer(data)) gz, err := gzip.NewReader(bytes.NewBuffer(data))
if err != nil { if err != nil {
return nil, fmt.Errorf("Read %%q: %%v", name, err) return nil, fmt.Errorf("Read %%q: %%v", name, err)
@ -155,14 +129,11 @@ func bindataRead(data []byte, name string) ([]byte, error) {
var buf bytes.Buffer var buf bytes.Buffer
_, err = io.Copy(&buf, gz) _, err = io.Copy(&buf, gz)
clErr := gz.Close() gz.Close()
if err != nil { if err != nil {
return nil, fmt.Errorf("Read %%q: %%v", name, err) return nil, fmt.Errorf("Read %%q: %%v", name, err)
} }
if clErr != nil {
return nil, err
}
return buf.Bytes(), nil return buf.Bytes(), nil
} }
@ -174,16 +145,11 @@ func bindataRead(data []byte, name string) ([]byte, error) {
func header_uncompressed_nomemcopy(w io.Writer) error { func header_uncompressed_nomemcopy(w io.Writer) error {
_, err := fmt.Fprintf(w, `import ( _, err := fmt.Fprintf(w, `import (
"fmt" "fmt"
"io/ioutil"
"os"
"path/filepath"
"reflect" "reflect"
"strings"
"time"
"unsafe" "unsafe"
) )
func bindataRead(data, name string) ([]byte, error) { func bindata_read(data, name string) ([]byte, error) {
var empty [0]byte var empty [0]byte
sx := (*reflect.StringHeader)(unsafe.Pointer(&data)) sx := (*reflect.StringHeader)(unsafe.Pointer(&data))
b := empty[:] b := empty[:]
@ -201,52 +167,11 @@ func bindataRead(data, name string) ([]byte, error) {
func header_uncompressed_memcopy(w io.Writer) error { func header_uncompressed_memcopy(w io.Writer) error {
_, err := fmt.Fprintf(w, `import ( _, err := fmt.Fprintf(w, `import (
"fmt" "fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
"time"
) )
`) `)
return err return err
} }
func header_release_common(w io.Writer) error {
_, err := fmt.Fprintf(w, `type asset struct {
bytes []byte
info os.FileInfo
}
type bindataFileInfo struct {
name string
size int64
mode os.FileMode
modTime time.Time
}
func (fi bindataFileInfo) Name() string {
return fi.name
}
func (fi bindataFileInfo) Size() int64 {
return fi.size
}
func (fi bindataFileInfo) Mode() os.FileMode {
return fi.mode
}
func (fi bindataFileInfo) ModTime() time.Time {
return fi.modTime
}
func (fi bindataFileInfo) IsDir() bool {
return false
}
func (fi bindataFileInfo) Sys() interface{} {
return nil
}
`)
return err
}
func compressed_nomemcopy(w io.Writer, asset *Asset, r io.Reader) error { func compressed_nomemcopy(w io.Writer, asset *Asset, r io.Reader) error {
_, err := fmt.Fprintf(w, `var _%s = "`, asset.Func) _, err := fmt.Fprintf(w, `var _%s = "`, asset.Func)
if err != nil { if err != nil {
@ -263,8 +188,8 @@ func compressed_nomemcopy(w io.Writer, asset *Asset, r io.Reader) error {
_, err = fmt.Fprintf(w, `" _, err = fmt.Fprintf(w, `"
func %sBytes() ([]byte, error) { func %s() ([]byte, error) {
return bindataRead( return bindata_read(
_%s, _%s,
%q, %q,
) )
@ -275,12 +200,14 @@ func %sBytes() ([]byte, error) {
} }
func compressed_memcopy(w io.Writer, asset *Asset, r io.Reader) error { func compressed_memcopy(w io.Writer, asset *Asset, r io.Reader) error {
_, err := fmt.Fprintf(w, `var _%s = []byte("`, asset.Func) _, err := fmt.Fprintf(w, `func %s() ([]byte, error) {
return bindata_read([]byte{`, asset.Func)
if err != nil { if err != nil {
return err return nil
} }
gz := gzip.NewWriter(&StringWriter{Writer: w}) gz := gzip.NewWriter(&ByteWriter{Writer: w})
_, err = io.Copy(gz, r) _, err = io.Copy(gz, r)
gz.Close() gz.Close()
@ -288,16 +215,13 @@ func compressed_memcopy(w io.Writer, asset *Asset, r io.Reader) error {
return err return err
} }
_, err = fmt.Fprintf(w, `") _, err = fmt.Fprintf(w, `
},
func %sBytes() ([]byte, error) {
return bindataRead(
_%s,
%q, %q,
) )
} }
`, asset.Func, asset.Func, asset.Name) `, asset.Name)
return err return err
} }
@ -314,8 +238,8 @@ func uncompressed_nomemcopy(w io.Writer, asset *Asset, r io.Reader) error {
_, err = fmt.Fprintf(w, `" _, err = fmt.Fprintf(w, `"
func %sBytes() ([]byte, error) { func %s() ([]byte, error) {
return bindataRead( return bindata_read(
_%s, _%s,
%q, %q,
) )
@ -326,62 +250,21 @@ func %sBytes() ([]byte, error) {
} }
func uncompressed_memcopy(w io.Writer, asset *Asset, r io.Reader) error { func uncompressed_memcopy(w io.Writer, asset *Asset, r io.Reader) error {
_, err := fmt.Fprintf(w, `var _%s = []byte(`, asset.Func) _, err := fmt.Fprintf(w, `func %s() ([]byte, error) {
return []byte{`, asset.Func)
if err != nil { if err != nil {
return err return err
} }
b, err := ioutil.ReadAll(r) _, err = io.Copy(&ByteWriter{Writer: w}, r)
if err != nil {
return err
}
if utf8.Valid(b) && !bytes.Contains(b, []byte{0}) {
fmt.Fprintf(w, "`%s`", sanitize(b))
} else {
fmt.Fprintf(w, "%+q", b)
}
_, err = fmt.Fprintf(w, `)
func %sBytes() ([]byte, error) {
return _%s, nil
}
`, asset.Func, asset.Func)
return err
}
func asset_release_common(w io.Writer, c *Config, asset *Asset) error {
fi, err := os.Stat(asset.Path)
if err != nil { if err != nil {
return err return err
} }
mode := uint(fi.Mode()) _, err = fmt.Fprintf(w, `
modTime := fi.ModTime().Unix() }, nil
size := fi.Size()
if c.NoMetadata {
mode = 0
modTime = 0
size = 0
}
if c.Mode > 0 {
mode = uint(os.ModePerm) & c.Mode
}
if c.ModTime > 0 {
modTime = c.ModTime
}
_, err = fmt.Fprintf(w, `func %s() (*asset, error) {
bytes, err := %sBytes()
if err != nil {
return nil, err
} }
info := bindataFileInfo{name: %q, size: %d, mode: os.FileMode(%d), modTime: time.Unix(%d, 0)} `)
a := &asset{bytes: bytes, info: info}
return a, nil
}
`, asset.Func, asset.Func, asset.Name, size, mode, modTime)
return err return err
} }

View File

@ -1,63 +0,0 @@
// 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"
)
func writeRestore(w io.Writer) error {
_, err := fmt.Fprintf(w, `
// RestoreAsset restores an asset under the given directory
func RestoreAsset(dir, name string) error {
data, err := Asset(name)
if err != nil {
return err
}
info, err := AssetInfo(name)
if err != nil {
return err
}
err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755))
if err != nil {
return err
}
err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
if err != nil {
return err
}
err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
if err != nil {
return err
}
return nil
}
// RestoreAssets restores an asset under the given directory recursively
func RestoreAssets(dir, name string) error {
children, err := AssetDir(name)
// File
if err != nil {
return RestoreAsset(dir, name)
}
// Dir
for _, child := range children {
err = RestoreAssets(dir, filepath.Join(name, child))
if err != nil {
return err
}
}
return nil
}
func _filePath(dir, name string) string {
cannonicalName := strings.Replace(name, "\\", "/", -1)
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
}
`)
return err
}

37
testdata/Makefile vendored
View File

@ -1,37 +0,0 @@
FILES:=$(wildcard out/*.go)
.PHONY: check
check: errcheck vet golint $(FILES:.go=.checked)
out/%.checked: out/%.go
errcheck $<
go tool vet --all $<
go tool vet --shadow $<
golint $<
$(GOPATH)/bin/go-bindata: $(wildcard ../*.go) $(wildcard ../**/*.go)
go install ../...
out/compress-memcopy.go: $(wildcard in/**/*) $(GOPATH)/bin/go-bindata
$(GOPATH)/bin/go-bindata -o $@ in/...
out/compress-nomemcopy.go: $(wildcard in/**/*) $(GOPATH)/bin/go-bindata
$(GOPATH)/bin/go-bindata -nomemcopy -o $@ in/...
out/debug.go: $(wildcard in/**/*) $(GOPATH)/bin/go-bindata
$(GOPATH)/bin/go-bindata -debug -o $@ in/...
out/nocompress-memcopy.go: $(wildcard in/**/*) $(GOPATH)/bin/go-bindata
$(GOPATH)/bin/go-bindata -nocompress -o $@ in/...
out/nocompress-nomemcopy.go: $(wildcard in/**/*) $(GOPATH)/bin/go-bindata
$(GOPATH)/bin/go-bindata -nocompress -nomemcopy -o $@ in/...
errcheck:
go get github.com/kisielk/errcheck
vet:
go get golang.org/x/tools/cmd/vet
golint:
go get github.com/golang/lint/golint

View File

@ -1 +0,0 @@
// sample file

View File

@ -1 +0,0 @@
// sample file

View File

@ -1,312 +1,86 @@
// Code generated by go-bindata.
// sources:
// in/a/test.asset
// in/b/test.asset
// in/c/test.asset
// in/test.asset
// DO NOT EDIT!
package main package main
import ( import (
"bytes" "bytes"
"compress/gzip" "compress/gzip"
"fmt"
"io" "io"
"io/ioutil" "log"
"os"
"path/filepath"
"strings"
"time"
) )
func bindataRead(data []byte, name string) ([]byte, error) { func bindata_read(data []byte, name string) []byte {
gz, err := gzip.NewReader(bytes.NewBuffer(data)) gz, err := gzip.NewReader(bytes.NewBuffer(data))
if err != nil { if err != nil {
return nil, fmt.Errorf("Read %q: %v", name, err) log.Fatalf("Read %q: %v", name, err)
} }
var buf bytes.Buffer var buf bytes.Buffer
_, err = io.Copy(&buf, gz) _, err = io.Copy(&buf, gz)
clErr := gz.Close() gz.Close()
if err != nil { if err != nil {
return nil, fmt.Errorf("Read %q: %v", name, err) log.Fatalf("Read %q: %v", name, err)
}
if clErr != nil {
return nil, err
} }
return buf.Bytes(), nil return buf.Bytes()
} }
type asset struct { func in_b_test_asset() []byte {
bytes []byte return bindata_read([]byte{
info os.FileInfo 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,
type bindataFileInfo struct { 0x00, 0x00, 0x00,
name string },
size int64
mode os.FileMode
modTime time.Time
}
func (fi bindataFileInfo) Name() string {
return fi.name
}
func (fi bindataFileInfo) Size() int64 {
return fi.size
}
func (fi bindataFileInfo) Mode() os.FileMode {
return fi.mode
}
func (fi bindataFileInfo) ModTime() time.Time {
return fi.modTime
}
func (fi bindataFileInfo) IsDir() bool {
return false
}
func (fi bindataFileInfo) Sys() interface{} {
return nil
}
var _inATestAsset = []byte("\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 inATestAssetBytes() ([]byte, error) {
return bindataRead(
_inATestAsset,
"in/a/test.asset",
)
}
func inATestAsset() (*asset, error) {
bytes, err := inATestAssetBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "in/a/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _inBTestAsset = []byte("\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 inBTestAssetBytes() ([]byte, error) {
return bindataRead(
_inBTestAsset,
"in/b/test.asset", "in/b/test.asset",
) )
} }
func inBTestAsset() (*asset, error) { func in_test_asset() []byte {
bytes, err := inBTestAssetBytes() return bindata_read([]byte{
if err != nil { 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x00, 0xff, 0xd2, 0xd7,
return nil, err 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,
info := bindataFileInfo{name: "in/b/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)} },
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _inCTestAsset = []byte("\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 inCTestAssetBytes() ([]byte, error) {
return bindataRead(
_inCTestAsset,
"in/c/test.asset",
)
}
func inCTestAsset() (*asset, error) {
bytes, err := inCTestAssetBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "in/c/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _inTestAsset = []byte("\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 inTestAssetBytes() ([]byte, error) {
return bindataRead(
_inTestAsset,
"in/test.asset", "in/test.asset",
) )
} }
func inTestAsset() (*asset, error) { func in_a_test_asset() []byte {
bytes, err := inTestAssetBytes() return bindata_read([]byte{
if err != nil { 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x00, 0xff, 0xd2, 0xd7,
return nil, err 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",
)
} }
info := bindataFileInfo{name: "in/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)} func in_c_test_asset() []byte {
a := &asset{bytes: bytes, info: info} return bindata_read([]byte{
return a, nil 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",
)
} }
// Asset loads and returns the asset for the given name. // Asset loads and returns the asset for the given name.
// It returns an error if the asset could not be found or // This returns nil of the asset could not be found.
// could not be loaded. func Asset(name string) []byte {
func Asset(name string) ([]byte, error) { if f, ok := _bindata[name]; ok {
cannonicalName := strings.Replace(name, "\\", "/", -1) return f()
if f, ok := _bindata[cannonicalName]; ok {
a, err := f()
if err != nil {
return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
} }
return a.bytes, nil return nil
}
return nil, fmt.Errorf("Asset %s not found", name)
}
// MustAsset is like Asset but panics when Asset would return an error.
// It simplifies safe initialization of global variables.
func MustAsset(name string) []byte {
a, err := Asset(name)
if err != nil {
panic("asset: Asset(" + name + "): " + err.Error())
}
return a
}
// AssetInfo loads and returns the asset info for the given name.
// It returns an error if the asset could not be found or
// could not be loaded.
func AssetInfo(name string) (os.FileInfo, error) {
cannonicalName := strings.Replace(name, "\\", "/", -1)
if f, ok := _bindata[cannonicalName]; ok {
a, err := f()
if err != nil {
return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
}
return a.info, nil
}
return nil, fmt.Errorf("AssetInfo %s not found", name)
}
// AssetNames returns the names of the assets.
func AssetNames() []string {
names := make([]string, 0, len(_bindata))
for name := range _bindata {
names = append(names, name)
}
return names
} }
// _bindata is a table, holding each asset generator, mapped to its name. // _bindata is a table, holding each asset generator, mapped to its name.
var _bindata = map[string]func() (*asset, error){ var _bindata = map[string]func() []byte{
"in/a/test.asset": inATestAsset, "in/b/test.asset": in_b_test_asset,
"in/b/test.asset": inBTestAsset, "in/test.asset": in_test_asset,
"in/c/test.asset": inCTestAsset, "in/a/test.asset": in_a_test_asset,
"in/test.asset": inTestAsset, "in/c/test.asset": in_c_test_asset,
} }
// AssetDir returns the file names below a certain
// directory embedded in the file by go-bindata.
// For example if you run go-bindata on data/... and data contains the
// following hierarchy:
// data/
// foo.txt
// img/
// a.png
// b.png
// then AssetDir("data") would return []string{"foo.txt", "img"}
// AssetDir("data/img") would return []string{"a.png", "b.png"}
// AssetDir("foo.txt") and AssetDir("notexist") would return an error
// AssetDir("") will return []string{"data"}.
func AssetDir(name string) ([]string, error) {
node := _bintree
if len(name) != 0 {
cannonicalName := strings.Replace(name, "\\", "/", -1)
pathList := strings.Split(cannonicalName, "/")
for _, p := range pathList {
node = node.Children[p]
if node == nil {
return nil, fmt.Errorf("Asset %s not found", name)
}
}
}
if node.Func != nil {
return nil, fmt.Errorf("Asset %s not found", name)
}
rv := make([]string, 0, len(node.Children))
for childName := range node.Children {
rv = append(rv, childName)
}
return rv, nil
}
type bintree struct {
Func func() (*asset, error)
Children map[string]*bintree
}
var _bintree = &bintree{nil, map[string]*bintree{
"in": &bintree{nil, map[string]*bintree{
"a": &bintree{nil, map[string]*bintree{
"test.asset": &bintree{inATestAsset, map[string]*bintree{}},
}},
"b": &bintree{nil, map[string]*bintree{
"test.asset": &bintree{inBTestAsset, map[string]*bintree{}},
}},
"c": &bintree{nil, map[string]*bintree{
"test.asset": &bintree{inCTestAsset, map[string]*bintree{}},
}},
"test.asset": &bintree{inTestAsset, map[string]*bintree{}},
}},
}}
// RestoreAsset restores an asset under the given directory
func RestoreAsset(dir, name string) error {
data, err := Asset(name)
if err != nil {
return err
}
info, err := AssetInfo(name)
if err != nil {
return err
}
err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755))
if err != nil {
return err
}
err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
if err != nil {
return err
}
err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
if err != nil {
return err
}
return nil
}
// RestoreAssets restores an asset under the given directory recursively
func RestoreAssets(dir, name string) error {
children, err := AssetDir(name)
// File
if err != nil {
return RestoreAsset(dir, name)
}
// Dir
for _, child := range children {
err = RestoreAssets(dir, filepath.Join(name, child))
if err != nil {
return err
}
}
return nil
}
func _filePath(dir, name string) string {
cannonicalName := strings.Replace(name, "\\", "/", -1)
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
}

View File

@ -1,312 +1,88 @@
// Code generated by go-bindata.
// sources:
// in/a/test.asset
// in/b/test.asset
// in/c/test.asset
// in/test.asset
// DO NOT EDIT!
package main package main
import ( import (
"bytes" "bytes"
"compress/gzip" "compress/gzip"
"fmt"
"io" "io"
"io/ioutil" "log"
"os" "reflect"
"path/filepath" "unsafe"
"strings"
"time"
) )
func bindataRead(data, name string) ([]byte, error) { func bindata_read(data, name string) []byte {
gz, err := gzip.NewReader(strings.NewReader(data)) 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 { if err != nil {
return nil, fmt.Errorf("Read %q: %v", name, err) log.Fatalf("Read %q: %v", name, err)
} }
var buf bytes.Buffer var buf bytes.Buffer
_, err = io.Copy(&buf, gz) _, err = io.Copy(&buf, gz)
clErr := gz.Close() gz.Close()
if err != nil { if err != nil {
return nil, fmt.Errorf("Read %q: %v", name, err) log.Fatalf("Read %q: %v", name, err)
}
if clErr != nil {
return nil, err
} }
return buf.Bytes(), nil return buf.Bytes()
} }
type asset struct { 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"
bytes []byte
info os.FileInfo
}
type bindataFileInfo struct { func in_b_test_asset() []byte {
name string return bindata_read(
size int64 _in_b_test_asset,
mode os.FileMode
modTime time.Time
}
func (fi bindataFileInfo) Name() string {
return fi.name
}
func (fi bindataFileInfo) Size() int64 {
return fi.size
}
func (fi bindataFileInfo) Mode() os.FileMode {
return fi.mode
}
func (fi bindataFileInfo) ModTime() time.Time {
return fi.modTime
}
func (fi bindataFileInfo) IsDir() bool {
return false
}
func (fi bindataFileInfo) Sys() interface{} {
return nil
}
var _inATestAsset = "\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 inATestAssetBytes() ([]byte, error) {
return bindataRead(
_inATestAsset,
"in/a/test.asset",
)
}
func inATestAsset() (*asset, error) {
bytes, err := inATestAssetBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "in/a/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _inBTestAsset = "\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 inBTestAssetBytes() ([]byte, error) {
return bindataRead(
_inBTestAsset,
"in/b/test.asset", "in/b/test.asset",
) )
} }
func inBTestAsset() (*asset, error) { 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"
bytes, err := inBTestAssetBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "in/b/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)} func in_test_asset() []byte {
a := &asset{bytes: bytes, info: info} return bindata_read(
return a, nil _in_test_asset,
}
var _inCTestAsset = "\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 inCTestAssetBytes() ([]byte, error) {
return bindataRead(
_inCTestAsset,
"in/c/test.asset",
)
}
func inCTestAsset() (*asset, error) {
bytes, err := inCTestAssetBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "in/c/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _inTestAsset = "\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 inTestAssetBytes() ([]byte, error) {
return bindataRead(
_inTestAsset,
"in/test.asset", "in/test.asset",
) )
} }
func inTestAsset() (*asset, error) { 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"
bytes, err := inTestAssetBytes()
if err != nil { func in_a_test_asset() []byte {
return nil, err return bindata_read(
_in_a_test_asset,
"in/a/test.asset",
)
} }
info := bindataFileInfo{name: "in/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)} 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"
a := &asset{bytes: bytes, info: info}
return a, nil func in_c_test_asset() []byte {
return bindata_read(
_in_c_test_asset,
"in/c/test.asset",
)
} }
// Asset loads and returns the asset for the given name. // Asset loads and returns the asset for the given name.
// It returns an error if the asset could not be found or // This returns nil of the asset could not be found.
// could not be loaded. func Asset(name string) []byte {
func Asset(name string) ([]byte, error) { if f, ok := _bindata[name]; ok {
cannonicalName := strings.Replace(name, "\\", "/", -1) return f()
if f, ok := _bindata[cannonicalName]; ok {
a, err := f()
if err != nil {
return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
} }
return a.bytes, nil return nil
}
return nil, fmt.Errorf("Asset %s not found", name)
}
// MustAsset is like Asset but panics when Asset would return an error.
// It simplifies safe initialization of global variables.
func MustAsset(name string) []byte {
a, err := Asset(name)
if err != nil {
panic("asset: Asset(" + name + "): " + err.Error())
}
return a
}
// AssetInfo loads and returns the asset info for the given name.
// It returns an error if the asset could not be found or
// could not be loaded.
func AssetInfo(name string) (os.FileInfo, error) {
cannonicalName := strings.Replace(name, "\\", "/", -1)
if f, ok := _bindata[cannonicalName]; ok {
a, err := f()
if err != nil {
return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
}
return a.info, nil
}
return nil, fmt.Errorf("AssetInfo %s not found", name)
}
// AssetNames returns the names of the assets.
func AssetNames() []string {
names := make([]string, 0, len(_bindata))
for name := range _bindata {
names = append(names, name)
}
return names
} }
// _bindata is a table, holding each asset generator, mapped to its name. // _bindata is a table, holding each asset generator, mapped to its name.
var _bindata = map[string]func() (*asset, error){ var _bindata = map[string]func() []byte{
"in/a/test.asset": inATestAsset, "in/b/test.asset": in_b_test_asset,
"in/b/test.asset": inBTestAsset, "in/test.asset": in_test_asset,
"in/c/test.asset": inCTestAsset, "in/a/test.asset": in_a_test_asset,
"in/test.asset": inTestAsset, "in/c/test.asset": in_c_test_asset,
} }
// AssetDir returns the file names below a certain
// directory embedded in the file by go-bindata.
// For example if you run go-bindata on data/... and data contains the
// following hierarchy:
// data/
// foo.txt
// img/
// a.png
// b.png
// then AssetDir("data") would return []string{"foo.txt", "img"}
// AssetDir("data/img") would return []string{"a.png", "b.png"}
// AssetDir("foo.txt") and AssetDir("notexist") would return an error
// AssetDir("") will return []string{"data"}.
func AssetDir(name string) ([]string, error) {
node := _bintree
if len(name) != 0 {
cannonicalName := strings.Replace(name, "\\", "/", -1)
pathList := strings.Split(cannonicalName, "/")
for _, p := range pathList {
node = node.Children[p]
if node == nil {
return nil, fmt.Errorf("Asset %s not found", name)
}
}
}
if node.Func != nil {
return nil, fmt.Errorf("Asset %s not found", name)
}
rv := make([]string, 0, len(node.Children))
for childName := range node.Children {
rv = append(rv, childName)
}
return rv, nil
}
type bintree struct {
Func func() (*asset, error)
Children map[string]*bintree
}
var _bintree = &bintree{nil, map[string]*bintree{
"in": &bintree{nil, map[string]*bintree{
"a": &bintree{nil, map[string]*bintree{
"test.asset": &bintree{inATestAsset, map[string]*bintree{}},
}},
"b": &bintree{nil, map[string]*bintree{
"test.asset": &bintree{inBTestAsset, map[string]*bintree{}},
}},
"c": &bintree{nil, map[string]*bintree{
"test.asset": &bintree{inCTestAsset, map[string]*bintree{}},
}},
"test.asset": &bintree{inTestAsset, map[string]*bintree{}},
}},
}}
// RestoreAsset restores an asset under the given directory
func RestoreAsset(dir, name string) error {
data, err := Asset(name)
if err != nil {
return err
}
info, err := AssetInfo(name)
if err != nil {
return err
}
err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755))
if err != nil {
return err
}
err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
if err != nil {
return err
}
err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
if err != nil {
return err
}
return nil
}
// RestoreAssets restores an asset under the given directory recursively
func RestoreAssets(dir, name string) error {
children, err := AssetDir(name)
// File
if err != nil {
return RestoreAsset(dir, name)
}
// Dir
for _, child := range children {
err = RestoreAssets(dir, filepath.Join(name, child))
if err != nil {
return err
}
}
return nil
}
func _filePath(dir, name string) string {
cannonicalName := strings.Replace(name, "\\", "/", -1)
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
}

285
testdata/out/debug.go vendored
View File

@ -1,263 +1,80 @@
// Code generated by go-bindata.
// sources:
// in/a/test.asset
// in/b/test.asset
// in/c/test.asset
// in/test.asset
// DO NOT EDIT!
package main package main
import ( import (
"fmt" "bytes"
"io/ioutil" "io"
"log"
"os" "os"
"path/filepath"
"strings"
) )
// bindataRead reads the given file from disk. It returns an error on failure. // bindata_read reads the given file from disk.
func bindataRead(path, name string) ([]byte, error) { // It panics if anything went wrong.
buf, err := ioutil.ReadFile(path) func bindata_read(path, name string) []byte {
fd, err := os.Open(path)
if err != nil { if err != nil {
err = fmt.Errorf("Error reading asset %s at %s: %v", name, path, err) log.Fatalf("Read %s: %v", name, err)
}
return buf, err
} }
type asset struct { defer fd.Close()
bytes []byte
info os.FileInfo
}
// inATestAsset reads file data from disk. It returns an error on failure. var buf bytes.Buffer
func inATestAsset() (*asset, error) { _, err = io.Copy(&buf, fd)
path := "/home/ts/code/go/src/git.kirsle.net/go/bindata/testdata/in/a/test.asset"
name := "in/a/test.asset"
bytes, err := bindataRead(path, name)
if err != nil { if err != nil {
return nil, err log.Fatalf("Read %s: %v", name, err)
} }
fi, err := os.Stat(path) return buf.Bytes()
if err != nil {
err = fmt.Errorf("Error reading asset info %s at %s: %v", name, path, err)
} }
a := &asset{bytes: bytes, info: fi} // in_b_test_asset reads file data from disk.
return a, err // It panics if something went wrong in the process.
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",
)
} }
// inBTestAsset reads file data from disk. It returns an error on failure. // in_test_asset reads file data from disk.
func inBTestAsset() (*asset, error) { // It panics if something went wrong in the process.
path := "/home/ts/code/go/src/git.kirsle.net/go/bindata/testdata/in/b/test.asset" func in_test_asset() []byte {
name := "in/b/test.asset" return bindata_read(
bytes, err := bindataRead(path, name) "/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/test.asset",
if err != nil { "in/test.asset",
return nil, err )
} }
fi, err := os.Stat(path) // in_a_test_asset reads file data from disk.
if err != nil { // It panics if something went wrong in the process.
err = fmt.Errorf("Error reading asset info %s at %s: %v", name, path, err) 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",
)
} }
a := &asset{bytes: bytes, info: fi} // in_c_test_asset reads file data from disk.
return a, err // It panics if something went wrong in the process.
} func in_c_test_asset() []byte {
return bindata_read(
// inCTestAsset reads file data from disk. It returns an error on failure. "/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/c/test.asset",
func inCTestAsset() (*asset, error) { "in/c/test.asset",
path := "/home/ts/code/go/src/git.kirsle.net/go/bindata/testdata/in/c/test.asset" )
name := "in/c/test.asset"
bytes, err := bindataRead(path, name)
if err != nil {
return nil, err
}
fi, err := os.Stat(path)
if err != nil {
err = fmt.Errorf("Error reading asset info %s at %s: %v", name, path, err)
}
a := &asset{bytes: bytes, info: fi}
return a, err
}
// inTestAsset reads file data from disk. It returns an error on failure.
func inTestAsset() (*asset, error) {
path := "/home/ts/code/go/src/git.kirsle.net/go/bindata/testdata/in/test.asset"
name := "in/test.asset"
bytes, err := bindataRead(path, name)
if err != nil {
return nil, err
}
fi, err := os.Stat(path)
if err != nil {
err = fmt.Errorf("Error reading asset info %s at %s: %v", name, path, err)
}
a := &asset{bytes: bytes, info: fi}
return a, err
} }
// Asset loads and returns the asset for the given name. // Asset loads and returns the asset for the given name.
// It returns an error if the asset could not be found or // This returns nil of the asset could not be found.
// could not be loaded. func Asset(name string) []byte {
func Asset(name string) ([]byte, error) { if f, ok := _bindata[name]; ok {
cannonicalName := strings.Replace(name, "\\", "/", -1) return f()
if f, ok := _bindata[cannonicalName]; ok {
a, err := f()
if err != nil {
return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
} }
return a.bytes, nil return nil
}
return nil, fmt.Errorf("Asset %s not found", name)
}
// MustAsset is like Asset but panics when Asset would return an error.
// It simplifies safe initialization of global variables.
func MustAsset(name string) []byte {
a, err := Asset(name)
if err != nil {
panic("asset: Asset(" + name + "): " + err.Error())
}
return a
}
// AssetInfo loads and returns the asset info for the given name.
// It returns an error if the asset could not be found or
// could not be loaded.
func AssetInfo(name string) (os.FileInfo, error) {
cannonicalName := strings.Replace(name, "\\", "/", -1)
if f, ok := _bindata[cannonicalName]; ok {
a, err := f()
if err != nil {
return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
}
return a.info, nil
}
return nil, fmt.Errorf("AssetInfo %s not found", name)
}
// AssetNames returns the names of the assets.
func AssetNames() []string {
names := make([]string, 0, len(_bindata))
for name := range _bindata {
names = append(names, name)
}
return names
} }
// _bindata is a table, holding each asset generator, mapped to its name. // _bindata is a table, holding each asset generator, mapped to its name.
var _bindata = map[string]func() (*asset, error){ var _bindata = map[string]func() []byte{
"in/a/test.asset": inATestAsset, "in/b/test.asset": in_b_test_asset,
"in/b/test.asset": inBTestAsset, "in/test.asset": in_test_asset,
"in/c/test.asset": inCTestAsset, "in/a/test.asset": in_a_test_asset,
"in/test.asset": inTestAsset, "in/c/test.asset": in_c_test_asset,
} }
// AssetDir returns the file names below a certain
// directory embedded in the file by go-bindata.
// For example if you run go-bindata on data/... and data contains the
// following hierarchy:
// data/
// foo.txt
// img/
// a.png
// b.png
// then AssetDir("data") would return []string{"foo.txt", "img"}
// AssetDir("data/img") would return []string{"a.png", "b.png"}
// AssetDir("foo.txt") and AssetDir("notexist") would return an error
// AssetDir("") will return []string{"data"}.
func AssetDir(name string) ([]string, error) {
node := _bintree
if len(name) != 0 {
cannonicalName := strings.Replace(name, "\\", "/", -1)
pathList := strings.Split(cannonicalName, "/")
for _, p := range pathList {
node = node.Children[p]
if node == nil {
return nil, fmt.Errorf("Asset %s not found", name)
}
}
}
if node.Func != nil {
return nil, fmt.Errorf("Asset %s not found", name)
}
rv := make([]string, 0, len(node.Children))
for childName := range node.Children {
rv = append(rv, childName)
}
return rv, nil
}
type bintree struct {
Func func() (*asset, error)
Children map[string]*bintree
}
var _bintree = &bintree{nil, map[string]*bintree{
"in": &bintree{nil, map[string]*bintree{
"a": &bintree{nil, map[string]*bintree{
"test.asset": &bintree{inATestAsset, map[string]*bintree{}},
}},
"b": &bintree{nil, map[string]*bintree{
"test.asset": &bintree{inBTestAsset, map[string]*bintree{}},
}},
"c": &bintree{nil, map[string]*bintree{
"test.asset": &bintree{inCTestAsset, map[string]*bintree{}},
}},
"test.asset": &bintree{inTestAsset, map[string]*bintree{}},
}},
}}
// RestoreAsset restores an asset under the given directory
func RestoreAsset(dir, name string) error {
data, err := Asset(name)
if err != nil {
return err
}
info, err := AssetInfo(name)
if err != nil {
return err
}
err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755))
if err != nil {
return err
}
err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
if err != nil {
return err
}
err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
if err != nil {
return err
}
return nil
}
// RestoreAssets restores an asset under the given directory recursively
func RestoreAssets(dir, name string) error {
children, err := AssetDir(name)
// File
if err != nil {
return RestoreAsset(dir, name)
}
// Dir
for _, child := range children {
err = RestoreAssets(dir, filepath.Join(name, child))
if err != nil {
return err
}
}
return nil
}
func _filePath(dir, name string) string {
cannonicalName := strings.Replace(name, "\\", "/", -1)
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
}

View File

@ -1,259 +0,0 @@
package main
import (
"fmt"
"io/ioutil"
"strings"
"os"
"path"
"path/filepath"
)
// bindata_read reads the given file from disk. It returns an error on failure.
func bindata_read(path, name string) ([]byte, error) {
buf, err := ioutil.ReadFile(path)
if err != nil {
err = fmt.Errorf("Error reading asset %s at %s: %v", name, path, err)
}
return buf, err
}
type asset struct {
bytes []byte
info os.FileInfo
}
// in_a_test_asset reads file data from disk. It returns an error on failure.
func in_a_test_asset() (*asset, error) {
path := "/Users/tamird/src/go/src/git.kirsle.net/go/bindata/testdata/in/a/test.asset"
name := "in/a/test.asset"
bytes, err := bindata_read(path, name)
if err != nil {
return nil, err
}
fi, err := os.Stat(path)
if err != nil {
err = fmt.Errorf("Error reading asset info %s at %s: %v", name, path, err)
}
a := &asset{bytes: bytes, info: fi}
return a, err
}
// in_b_test_asset reads file data from disk. It returns an error on failure.
func in_b_test_asset() (*asset, error) {
path := "/Users/tamird/src/go/src/git.kirsle.net/go/bindata/testdata/in/b/test.asset"
name := "in/b/test.asset"
bytes, err := bindata_read(path, name)
if err != nil {
return nil, err
}
fi, err := os.Stat(path)
if err != nil {
err = fmt.Errorf("Error reading asset info %s at %s: %v", name, path, err)
}
a := &asset{bytes: bytes, info: fi}
return a, err
}
// in_c_test_asset reads file data from disk. It returns an error on failure.
func in_c_test_asset() (*asset, error) {
path := "/Users/tamird/src/go/src/git.kirsle.net/go/bindata/testdata/in/c/test.asset"
name := "in/c/test.asset"
bytes, err := bindata_read(path, name)
if err != nil {
return nil, err
}
fi, err := os.Stat(path)
if err != nil {
err = fmt.Errorf("Error reading asset info %s at %s: %v", name, path, err)
}
a := &asset{bytes: bytes, info: fi}
return a, err
}
// in_test_asset reads file data from disk. It returns an error on failure.
func in_test_asset() (*asset, error) {
path := "/Users/tamird/src/go/src/git.kirsle.net/go/bindata/testdata/in/test.asset"
name := "in/test.asset"
bytes, err := bindata_read(path, name)
if err != nil {
return nil, err
}
fi, err := os.Stat(path)
if err != nil {
err = fmt.Errorf("Error reading asset info %s at %s: %v", name, path, err)
}
a := &asset{bytes: bytes, info: fi}
return a, err
}
// Asset loads and returns the asset for the given name.
// It returns an error if the asset could not be found or
// could not be loaded.
func Asset(name string) ([]byte, error) {
cannonicalName := strings.Replace(name, "\\", "/", -1)
if f, ok := _bindata[cannonicalName]; ok {
a, err := f()
if err != nil {
return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
}
return a.bytes, nil
}
return nil, fmt.Errorf("Asset %s not found", name)
}
// MustAsset is like Asset but panics when Asset would return an error.
// It simplifies safe initialization of global variables.
func MustAsset(name string) []byte {
a, err := Asset(name)
if (err != nil) {
panic("asset: Asset(" + name + "): " + err.Error())
}
return a
}
// AssetInfo loads and returns the asset info for the given name.
// It returns an error if the asset could not be found or
// could not be loaded.
func AssetInfo(name string) (os.FileInfo, error) {
cannonicalName := strings.Replace(name, "\\", "/", -1)
if f, ok := _bindata[cannonicalName]; ok {
a, err := f()
if err != nil {
return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
}
return a.info, nil
}
return nil, fmt.Errorf("AssetInfo %s not found", name)
}
// AssetNames returns the names of the assets.
func AssetNames() []string {
names := make([]string, 0, len(_bindata))
for name := range _bindata {
names = append(names, name)
}
return names
}
// _bindata is a table, holding each asset generator, mapped to its name.
var _bindata = map[string]func() (*asset, error){
"in/a/test.asset": in_a_test_asset,
"in/b/test.asset": in_b_test_asset,
"in/c/test.asset": in_c_test_asset,
"in/test.asset": in_test_asset,
}
// AssetDir returns the file names below a certain
// directory embedded in the file by go-bindata.
// For example if you run go-bindata on data/... and data contains the
// following hierarchy:
// data/
// foo.txt
// img/
// a.png
// b.png
// then AssetDir("data") would return []string{"foo.txt", "img"}
// AssetDir("data/img") would return []string{"a.png", "b.png"}
// AssetDir("foo.txt") and AssetDir("notexist") would return an error
// AssetDir("") will return []string{"data"}.
func AssetDir(name string) ([]string, error) {
node := _bintree
if len(name) != 0 {
cannonicalName := strings.Replace(name, "\\", "/", -1)
pathList := strings.Split(cannonicalName, "/")
for _, p := range pathList {
node = node.Children[p]
if node == nil {
return nil, fmt.Errorf("Asset %s not found", name)
}
}
}
if node.Func != nil {
return nil, fmt.Errorf("Asset %s not found", name)
}
rv := make([]string, 0, len(node.Children))
for name := range node.Children {
rv = append(rv, name)
}
return rv, nil
}
type _bintree_t struct {
Func func() (*asset, error)
Children map[string]*_bintree_t
}
var _bintree = &_bintree_t{nil, map[string]*_bintree_t{
"in": &_bintree_t{nil, map[string]*_bintree_t{
"a": &_bintree_t{nil, map[string]*_bintree_t{
"test.asset": &_bintree_t{in_a_test_asset, map[string]*_bintree_t{
}},
}},
"b": &_bintree_t{nil, map[string]*_bintree_t{
"test.asset": &_bintree_t{in_b_test_asset, map[string]*_bintree_t{
}},
}},
"c": &_bintree_t{nil, map[string]*_bintree_t{
"test.asset": &_bintree_t{in_c_test_asset, map[string]*_bintree_t{
}},
}},
"test.asset": &_bintree_t{in_test_asset, map[string]*_bintree_t{
}},
}},
}}
// Restore an asset under the given directory
func RestoreAsset(dir, name string) error {
data, err := Asset(name)
if err != nil {
return err
}
info, err := AssetInfo(name)
if err != nil {
return err
}
err = os.MkdirAll(_filePath(dir, path.Dir(name)), os.FileMode(0755))
if err != nil {
return err
}
err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
if err != nil {
return err
}
err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
if err != nil {
return err
}
return nil
}
// Restore assets under the given directory recursively
func RestoreAssets(dir, name string) error {
children, err := AssetDir(name)
if err != nil { // File
return RestoreAsset(dir, name)
} else { // Dir
for _, child := range children {
err = RestoreAssets(dir, path.Join(name, child))
if err != nil {
return err
}
}
}
return nil
}
func _filePath(dir, name string) string {
cannonicalName := strings.Replace(name, "\\", "/", -1)
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
}

View File

@ -1,280 +1,46 @@
// Code generated by go-bindata.
// sources:
// in/a/test.asset
// in/b/test.asset
// in/c/test.asset
// in/test.asset
// DO NOT EDIT!
package main package main
import ( func in_b_test_asset() []byte {
"fmt" return []byte{
"io/ioutil" 0x2f, 0x2f, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x66, 0x69,
"os" 0x6c, 0x65, 0x0a,
"path/filepath" }
"strings"
"time"
)
type asset struct {
bytes []byte
info os.FileInfo
} }
type bindataFileInfo struct { func in_test_asset() []byte {
name string return []byte{
size int64 0x2f, 0x2f, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x66, 0x69,
mode os.FileMode 0x6c, 0x65, 0x0a,
modTime time.Time }
} }
func (fi bindataFileInfo) Name() string { func in_a_test_asset() []byte {
return fi.name return []byte{
0x2f, 0x2f, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x66, 0x69,
0x6c, 0x65, 0x0a,
} }
func (fi bindataFileInfo) Size() int64 {
return fi.size
}
func (fi bindataFileInfo) Mode() os.FileMode {
return fi.mode
}
func (fi bindataFileInfo) ModTime() time.Time {
return fi.modTime
}
func (fi bindataFileInfo) IsDir() bool {
return false
}
func (fi bindataFileInfo) Sys() interface{} {
return nil
} }
var _inATestAsset = []byte(`// sample file func in_c_test_asset() []byte {
`) return []byte{
0x2f, 0x2f, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x66, 0x69,
func inATestAssetBytes() ([]byte, error) { 0x6c, 0x65, 0x0a,
return _inATestAsset, nil
} }
func inATestAsset() (*asset, error) {
bytes, err := inATestAssetBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "in/a/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _inBTestAsset = []byte(`// sample file
`)
func inBTestAssetBytes() ([]byte, error) {
return _inBTestAsset, nil
}
func inBTestAsset() (*asset, error) {
bytes, err := inBTestAssetBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "in/b/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _inCTestAsset = []byte(`// sample file
`)
func inCTestAssetBytes() ([]byte, error) {
return _inCTestAsset, nil
}
func inCTestAsset() (*asset, error) {
bytes, err := inCTestAssetBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "in/c/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _inTestAsset = []byte(`// sample file
`)
func inTestAssetBytes() ([]byte, error) {
return _inTestAsset, nil
}
func inTestAsset() (*asset, error) {
bytes, err := inTestAssetBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "in/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
} }
// Asset loads and returns the asset for the given name. // Asset loads and returns the asset for the given name.
// It returns an error if the asset could not be found or // This returns nil of the asset could not be found.
// could not be loaded. func Asset(name string) []byte {
func Asset(name string) ([]byte, error) { if f, ok := _bindata[name]; ok {
cannonicalName := strings.Replace(name, "\\", "/", -1) return f()
if f, ok := _bindata[cannonicalName]; ok {
a, err := f()
if err != nil {
return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
} }
return a.bytes, nil return nil
}
return nil, fmt.Errorf("Asset %s not found", name)
}
// MustAsset is like Asset but panics when Asset would return an error.
// It simplifies safe initialization of global variables.
func MustAsset(name string) []byte {
a, err := Asset(name)
if err != nil {
panic("asset: Asset(" + name + "): " + err.Error())
}
return a
}
// AssetInfo loads and returns the asset info for the given name.
// It returns an error if the asset could not be found or
// could not be loaded.
func AssetInfo(name string) (os.FileInfo, error) {
cannonicalName := strings.Replace(name, "\\", "/", -1)
if f, ok := _bindata[cannonicalName]; ok {
a, err := f()
if err != nil {
return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
}
return a.info, nil
}
return nil, fmt.Errorf("AssetInfo %s not found", name)
}
// AssetNames returns the names of the assets.
func AssetNames() []string {
names := make([]string, 0, len(_bindata))
for name := range _bindata {
names = append(names, name)
}
return names
} }
// _bindata is a table, holding each asset generator, mapped to its name. // _bindata is a table, holding each asset generator, mapped to its name.
var _bindata = map[string]func() (*asset, error){ var _bindata = map[string]func() []byte{
"in/a/test.asset": inATestAsset, "in/b/test.asset": in_b_test_asset,
"in/b/test.asset": inBTestAsset, "in/test.asset": in_test_asset,
"in/c/test.asset": inCTestAsset, "in/a/test.asset": in_a_test_asset,
"in/test.asset": inTestAsset, "in/c/test.asset": in_c_test_asset,
} }
// AssetDir returns the file names below a certain
// directory embedded in the file by go-bindata.
// For example if you run go-bindata on data/... and data contains the
// following hierarchy:
// data/
// foo.txt
// img/
// a.png
// b.png
// then AssetDir("data") would return []string{"foo.txt", "img"}
// AssetDir("data/img") would return []string{"a.png", "b.png"}
// AssetDir("foo.txt") and AssetDir("notexist") would return an error
// AssetDir("") will return []string{"data"}.
func AssetDir(name string) ([]string, error) {
node := _bintree
if len(name) != 0 {
cannonicalName := strings.Replace(name, "\\", "/", -1)
pathList := strings.Split(cannonicalName, "/")
for _, p := range pathList {
node = node.Children[p]
if node == nil {
return nil, fmt.Errorf("Asset %s not found", name)
}
}
}
if node.Func != nil {
return nil, fmt.Errorf("Asset %s not found", name)
}
rv := make([]string, 0, len(node.Children))
for childName := range node.Children {
rv = append(rv, childName)
}
return rv, nil
}
type bintree struct {
Func func() (*asset, error)
Children map[string]*bintree
}
var _bintree = &bintree{nil, map[string]*bintree{
"in": &bintree{nil, map[string]*bintree{
"a": &bintree{nil, map[string]*bintree{
"test.asset": &bintree{inATestAsset, map[string]*bintree{}},
}},
"b": &bintree{nil, map[string]*bintree{
"test.asset": &bintree{inBTestAsset, map[string]*bintree{}},
}},
"c": &bintree{nil, map[string]*bintree{
"test.asset": &bintree{inCTestAsset, map[string]*bintree{}},
}},
"test.asset": &bintree{inTestAsset, map[string]*bintree{}},
}},
}}
// RestoreAsset restores an asset under the given directory
func RestoreAsset(dir, name string) error {
data, err := Asset(name)
if err != nil {
return err
}
info, err := AssetInfo(name)
if err != nil {
return err
}
err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755))
if err != nil {
return err
}
err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
if err != nil {
return err
}
err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
if err != nil {
return err
}
return nil
}
// RestoreAssets restores an asset under the given directory recursively
func RestoreAssets(dir, name string) error {
children, err := AssetDir(name)
// File
if err != nil {
return RestoreAsset(dir, name)
}
// Dir
for _, child := range children {
err = RestoreAssets(dir, filepath.Join(name, child))
if err != nil {
return err
}
}
return nil
}
func _filePath(dir, name string) string {
cannonicalName := strings.Replace(name, "\\", "/", -1)
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
}

View File

@ -1,25 +1,11 @@
// Code generated by go-bindata.
// sources:
// in/a/test.asset
// in/b/test.asset
// in/c/test.asset
// in/test.asset
// DO NOT EDIT!
package main package main
import ( import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"reflect" "reflect"
"strings"
"time"
"unsafe" "unsafe"
) )
func bindataRead(data, name string) ([]byte, error) { func bindata_read(data, name string) []byte {
var empty [0]byte var empty [0]byte
sx := (*reflect.StringHeader)(unsafe.Pointer(&data)) sx := (*reflect.StringHeader)(unsafe.Pointer(&data))
b := empty[:] b := empty[:]
@ -27,276 +13,58 @@ func bindataRead(data, name string) ([]byte, error) {
bx.Data = sx.Data bx.Data = sx.Data
bx.Len = len(data) bx.Len = len(data)
bx.Cap = bx.Len bx.Cap = bx.Len
return b, nil return b
} }
type asset struct { var _in_b_test_asset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a"
bytes []byte
info os.FileInfo
}
type bindataFileInfo struct { func in_b_test_asset() []byte {
name string return bindata_read(
size int64 _in_b_test_asset,
mode os.FileMode
modTime time.Time
}
func (fi bindataFileInfo) Name() string {
return fi.name
}
func (fi bindataFileInfo) Size() int64 {
return fi.size
}
func (fi bindataFileInfo) Mode() os.FileMode {
return fi.mode
}
func (fi bindataFileInfo) ModTime() time.Time {
return fi.modTime
}
func (fi bindataFileInfo) IsDir() bool {
return false
}
func (fi bindataFileInfo) Sys() interface{} {
return nil
}
var _inATestAsset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a"
func inATestAssetBytes() ([]byte, error) {
return bindataRead(
_inATestAsset,
"in/a/test.asset",
)
}
func inATestAsset() (*asset, error) {
bytes, err := inATestAssetBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "in/a/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _inBTestAsset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a"
func inBTestAssetBytes() ([]byte, error) {
return bindataRead(
_inBTestAsset,
"in/b/test.asset", "in/b/test.asset",
) )
} }
func inBTestAsset() (*asset, error) { var _in_test_asset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a"
bytes, err := inBTestAssetBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "in/b/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)} func in_test_asset() []byte {
a := &asset{bytes: bytes, info: info} return bindata_read(
return a, nil _in_test_asset,
}
var _inCTestAsset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a"
func inCTestAssetBytes() ([]byte, error) {
return bindataRead(
_inCTestAsset,
"in/c/test.asset",
)
}
func inCTestAsset() (*asset, error) {
bytes, err := inCTestAssetBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "in/c/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
a := &asset{bytes: bytes, info: info}
return a, nil
}
var _inTestAsset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a"
func inTestAssetBytes() ([]byte, error) {
return bindataRead(
_inTestAsset,
"in/test.asset", "in/test.asset",
) )
} }
func inTestAsset() (*asset, error) { var _in_a_test_asset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a"
bytes, err := inTestAssetBytes()
if err != nil { func in_a_test_asset() []byte {
return nil, err return bindata_read(
_in_a_test_asset,
"in/a/test.asset",
)
} }
info := bindataFileInfo{name: "in/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)} var _in_c_test_asset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a"
a := &asset{bytes: bytes, info: info}
return a, nil func in_c_test_asset() []byte {
return bindata_read(
_in_c_test_asset,
"in/c/test.asset",
)
} }
// Asset loads and returns the asset for the given name. // Asset loads and returns the asset for the given name.
// It returns an error if the asset could not be found or // This returns nil of the asset could not be found.
// could not be loaded. func Asset(name string) []byte {
func Asset(name string) ([]byte, error) { if f, ok := _bindata[name]; ok {
cannonicalName := strings.Replace(name, "\\", "/", -1) return f()
if f, ok := _bindata[cannonicalName]; ok {
a, err := f()
if err != nil {
return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
} }
return a.bytes, nil return nil
}
return nil, fmt.Errorf("Asset %s not found", name)
}
// MustAsset is like Asset but panics when Asset would return an error.
// It simplifies safe initialization of global variables.
func MustAsset(name string) []byte {
a, err := Asset(name)
if err != nil {
panic("asset: Asset(" + name + "): " + err.Error())
}
return a
}
// AssetInfo loads and returns the asset info for the given name.
// It returns an error if the asset could not be found or
// could not be loaded.
func AssetInfo(name string) (os.FileInfo, error) {
cannonicalName := strings.Replace(name, "\\", "/", -1)
if f, ok := _bindata[cannonicalName]; ok {
a, err := f()
if err != nil {
return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
}
return a.info, nil
}
return nil, fmt.Errorf("AssetInfo %s not found", name)
}
// AssetNames returns the names of the assets.
func AssetNames() []string {
names := make([]string, 0, len(_bindata))
for name := range _bindata {
names = append(names, name)
}
return names
} }
// _bindata is a table, holding each asset generator, mapped to its name. // _bindata is a table, holding each asset generator, mapped to its name.
var _bindata = map[string]func() (*asset, error){ var _bindata = map[string]func() []byte{
"in/a/test.asset": inATestAsset, "in/b/test.asset": in_b_test_asset,
"in/b/test.asset": inBTestAsset, "in/test.asset": in_test_asset,
"in/c/test.asset": inCTestAsset, "in/a/test.asset": in_a_test_asset,
"in/test.asset": inTestAsset, "in/c/test.asset": in_c_test_asset,
} }
// AssetDir returns the file names below a certain
// directory embedded in the file by go-bindata.
// For example if you run go-bindata on data/... and data contains the
// following hierarchy:
// data/
// foo.txt
// img/
// a.png
// b.png
// then AssetDir("data") would return []string{"foo.txt", "img"}
// AssetDir("data/img") would return []string{"a.png", "b.png"}
// AssetDir("foo.txt") and AssetDir("notexist") would return an error
// AssetDir("") will return []string{"data"}.
func AssetDir(name string) ([]string, error) {
node := _bintree
if len(name) != 0 {
cannonicalName := strings.Replace(name, "\\", "/", -1)
pathList := strings.Split(cannonicalName, "/")
for _, p := range pathList {
node = node.Children[p]
if node == nil {
return nil, fmt.Errorf("Asset %s not found", name)
}
}
}
if node.Func != nil {
return nil, fmt.Errorf("Asset %s not found", name)
}
rv := make([]string, 0, len(node.Children))
for childName := range node.Children {
rv = append(rv, childName)
}
return rv, nil
}
type bintree struct {
Func func() (*asset, error)
Children map[string]*bintree
}
var _bintree = &bintree{nil, map[string]*bintree{
"in": &bintree{nil, map[string]*bintree{
"a": &bintree{nil, map[string]*bintree{
"test.asset": &bintree{inATestAsset, map[string]*bintree{}},
}},
"b": &bintree{nil, map[string]*bintree{
"test.asset": &bintree{inBTestAsset, map[string]*bintree{}},
}},
"c": &bintree{nil, map[string]*bintree{
"test.asset": &bintree{inCTestAsset, map[string]*bintree{}},
}},
"test.asset": &bintree{inTestAsset, map[string]*bintree{}},
}},
}}
// RestoreAsset restores an asset under the given directory
func RestoreAsset(dir, name string) error {
data, err := Asset(name)
if err != nil {
return err
}
info, err := AssetInfo(name)
if err != nil {
return err
}
err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755))
if err != nil {
return err
}
err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
if err != nil {
return err
}
err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
if err != nil {
return err
}
return nil
}
// RestoreAssets restores an asset under the given directory recursively
func RestoreAssets(dir, name string) error {
children, err := AssetDir(name)
// File
if err != nil {
return RestoreAsset(dir, name)
}
// Dir
for _, child := range children {
err = RestoreAssets(dir, filepath.Join(name, child))
if err != nil {
return err
}
}
return nil
}
func _filePath(dir, name string) string {
cannonicalName := strings.Replace(name, "\\", "/", -1)
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
}

View File

@ -1 +0,0 @@
../symlinkSrc/file1

View File

@ -1 +0,0 @@
../symlinkSrc/

View File

@ -1 +0,0 @@
// test file 1

View File

@ -1 +0,0 @@
../symlinkRecursiveParent/

View File

@ -1 +0,0 @@
// symlink file 1

View File

@ -1 +0,0 @@
// symlink file 2

View File

@ -1 +0,0 @@
// symlink file 3

View File

@ -1 +0,0 @@
// symlink file 4

184
toc.go
View File

@ -7,139 +7,8 @@ package bindata
import ( import (
"fmt" "fmt"
"io" "io"
"sort"
"strings"
) )
type assetTree struct {
Asset Asset
Children map[string]*assetTree
}
func newAssetTree() *assetTree {
tree := &assetTree{}
tree.Children = make(map[string]*assetTree)
return tree
}
func (node *assetTree) child(name string) *assetTree {
rv, ok := node.Children[name]
if !ok {
rv = newAssetTree()
node.Children[name] = rv
}
return rv
}
func (root *assetTree) Add(route []string, asset Asset) {
for _, name := range route {
root = root.child(name)
}
root.Asset = asset
}
func ident(w io.Writer, n int) {
for i := 0; i < n; i++ {
w.Write([]byte{'\t'})
}
}
func (root *assetTree) funcOrNil() string {
if root.Asset.Func == "" {
return "nil"
} else {
return root.Asset.Func
}
}
func (root *assetTree) writeGoMap(w io.Writer, nident int) {
fmt.Fprintf(w, "&bintree{%s, map[string]*bintree{", root.funcOrNil())
if len(root.Children) > 0 {
io.WriteString(w, "\n")
// Sort to make output stable between invocations
filenames := make([]string, len(root.Children))
i := 0
for filename, _ := range root.Children {
filenames[i] = filename
i++
}
sort.Strings(filenames)
for _, p := range filenames {
ident(w, nident+1)
fmt.Fprintf(w, `"%s": `, p)
root.Children[p].writeGoMap(w, nident+1)
}
ident(w, nident)
}
io.WriteString(w, "}}")
if nident > 0 {
io.WriteString(w, ",")
}
io.WriteString(w, "\n")
}
func (root *assetTree) WriteAsGoMap(w io.Writer) error {
_, err := fmt.Fprint(w, `type bintree struct {
Func func() (*asset, error)
Children map[string]*bintree
}
var _bintree = `)
root.writeGoMap(w, 0)
return err
}
func writeTOCTree(w io.Writer, toc []Asset) error {
_, err := fmt.Fprintf(w, `// AssetDir returns the file names below a certain
// directory embedded in the file by go-bindata.
// For example if you run go-bindata on data/... and data contains the
// following hierarchy:
// data/
// foo.txt
// img/
// a.png
// b.png
// then AssetDir("data") would return []string{"foo.txt", "img"}
// AssetDir("data/img") would return []string{"a.png", "b.png"}
// AssetDir("foo.txt") and AssetDir("notexist") would return an error
// AssetDir("") will return []string{"data"}.
func AssetDir(name string) ([]string, error) {
node := _bintree
if len(name) != 0 {
cannonicalName := strings.Replace(name, "\\", "/", -1)
pathList := strings.Split(cannonicalName, "/")
for _, p := range pathList {
node = node.Children[p]
if node == nil {
return nil, fmt.Errorf("Asset %%s not found", name)
}
}
}
if node.Func != nil {
return nil, fmt.Errorf("Asset %%s not found", name)
}
rv := make([]string, 0, len(node.Children))
for childName := range node.Children {
rv = append(rv, childName)
}
return rv, nil
}
`)
if err != nil {
return err
}
tree := newAssetTree()
for i := range toc {
pathList := strings.Split(toc[i].Name, "/")
tree.Add(pathList, toc[i])
}
return tree.WriteAsGoMap(w)
}
// writeTOC writes the table of contents file. // writeTOC writes the table of contents file.
func writeTOC(w io.Writer, toc []Asset) error { func writeTOC(w io.Writer, toc []Asset) error {
err := writeTOCHeader(w) err := writeTOCHeader(w)
@ -159,58 +28,19 @@ func writeTOC(w io.Writer, toc []Asset) error {
// writeTOCHeader writes the table of contents file header. // writeTOCHeader writes the table of contents file header.
func writeTOCHeader(w io.Writer) error { func writeTOCHeader(w io.Writer) error {
_, err := fmt.Fprintf(w, `// Asset loads and returns the asset for the given name. _, err := fmt.Fprintf(w, `
// Asset loads and returns the asset for the given name.
// It returns an error if the asset could not be found or // It returns an error if the asset could not be found or
// could not be loaded. // could not be loaded.
func Asset(name string) ([]byte, error) { func Asset(name string) ([]byte, error) {
cannonicalName := strings.Replace(name, "\\", "/", -1) if f, ok := _bindata[name]; ok {
if f, ok := _bindata[cannonicalName]; ok { return f()
a, err := f()
if err != nil {
return nil, fmt.Errorf("Asset %%s can't read by error: %%v", name, err)
}
return a.bytes, nil
} }
return nil, fmt.Errorf("Asset %%s not found", name) return nil, fmt.Errorf("Asset %%s not found", name)
} }
// MustAsset is like Asset but panics when Asset would return an error.
// It simplifies safe initialization of global variables.
func MustAsset(name string) []byte {
a, err := Asset(name)
if err != nil {
panic("asset: Asset(" + name + "): " + err.Error())
}
return a
}
// AssetInfo loads and returns the asset info for the given name.
// It returns an error if the asset could not be found or
// could not be loaded.
func AssetInfo(name string) (os.FileInfo, error) {
cannonicalName := strings.Replace(name, "\\", "/", -1)
if f, ok := _bindata[cannonicalName]; ok {
a, err := f()
if err != nil {
return nil, fmt.Errorf("AssetInfo %%s can't read by error: %%v", name, err)
}
return a.info, nil
}
return nil, fmt.Errorf("AssetInfo %%s not found", name)
}
// AssetNames returns the names of the assets.
func AssetNames() []string {
names := make([]string, 0, len(_bindata))
for name := range _bindata {
names = append(names, name)
}
return names
}
// _bindata is a table, holding each asset generator, mapped to its name. // _bindata is a table, holding each asset generator, mapped to its name.
var _bindata = map[string]func() (*asset, error){ var _bindata = map[string] func() ([]byte, error) {
`) `)
return err return err
} }
@ -223,8 +53,8 @@ func writeTOCAsset(w io.Writer, asset *Asset) error {
// writeTOCFooter writes the table of contents file footer. // writeTOCFooter writes the table of contents file footer.
func writeTOCFooter(w io.Writer) error { func writeTOCFooter(w io.Writer) error {
_, err := fmt.Fprintf(w, `} _, err := fmt.Fprintf(w, `
}
`) `)
return err return err
} }