mirror of https://github.com/k3s-io/k3s
William Zhang
5 years ago
49 changed files with 2248 additions and 60 deletions
@ -0,0 +1,16 @@
|
||||
# Binaries for programs and plugins |
||||
*.exe |
||||
*.exe~ |
||||
*.dll |
||||
*.so |
||||
*.dylib |
||||
|
||||
# Test binary, build with `go test -c` |
||||
*.test |
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE |
||||
*.out |
||||
|
||||
# Goland project files |
||||
.idea/ |
||||
*.iml |
@ -0,0 +1 @@
|
||||
theme: jekyll-theme-cayman |
@ -0,0 +1,90 @@
|
||||
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) |
||||
} |
||||
} |
@ -0,0 +1,102 @@
|
||||
package bindata |
||||
|
||||
import ( |
||||
"fmt" |
||||
"io" |
||||
) |
||||
|
||||
func writeAssetFS(w io.Writer, c *Config) error { |
||||
if !c.HttpFileSystem { |
||||
return nil |
||||
} |
||||
|
||||
_, err := fmt.Fprintf(w, ` |
||||
type assetFile struct { |
||||
*bytes.Reader |
||||
name string |
||||
childInfos []os.FileInfo |
||||
childInfoOffset int |
||||
} |
||||
|
||||
type assetOperator struct{} |
||||
|
||||
// Open implement http.FileSystem interface
|
||||
func (f *assetOperator) Open(name string) (http.File, error) { |
||||
var err error |
||||
if len(name) > 0 && name[0] == '/' { |
||||
name = name[1:] |
||||
} |
||||
content, err := Asset(name) |
||||
if err == nil { |
||||
return &assetFile{name: name, Reader: bytes.NewReader(content)}, nil |
||||
} |
||||
children, err := AssetDir(name) |
||||
if err == nil { |
||||
childInfos := make([]os.FileInfo, 0, len(children)) |
||||
for _, child := range children { |
||||
childPath := filepath.Join(name, child) |
||||
info, errInfo := AssetInfo(filepath.Join(name, child)) |
||||
if errInfo == nil { |
||||
childInfos = append(childInfos, info) |
||||
} else { |
||||
childInfos = append(childInfos, newDirFileInfo(childPath)) |
||||
} |
||||
} |
||||
return &assetFile{name: name, childInfos: childInfos}, nil |
||||
} else { |
||||
// If the error is not found, return an error that will
|
||||
// result in a 404 error. Otherwise the server returns
|
||||
// a 500 error for files not found.
|
||||
if strings.Contains(err.Error(), "not found") { |
||||
return nil, os.ErrNotExist |
||||
} |
||||
return nil, err |
||||
} |
||||
} |
||||
|
||||
// Close no need do anything
|
||||
func (f *assetFile) Close() error { |
||||
return nil |
||||
} |
||||
|
||||
// Readdir read dir's children file info
|
||||
func (f *assetFile) Readdir(count int) ([]os.FileInfo, error) { |
||||
if len(f.childInfos) == 0 { |
||||
return nil, os.ErrNotExist |
||||
} |
||||
if count <= 0 { |
||||
return f.childInfos, nil |
||||
} |
||||
if f.childInfoOffset+count > len(f.childInfos) { |
||||
count = len(f.childInfos) - f.childInfoOffset |
||||
} |
||||
offset := f.childInfoOffset |
||||
f.childInfoOffset += count |
||||
return f.childInfos[offset : offset+count], nil |
||||
} |
||||
|
||||
// Stat read file info from asset item
|
||||
func (f *assetFile) Stat() (os.FileInfo, error) { |
||||
if len(f.childInfos) != 0 { |
||||
return newDirFileInfo(f.name), nil |
||||
} |
||||
return AssetInfo(f.name) |
||||
} |
||||
|
||||
// newDirFileInfo return default dir file info
|
||||
func newDirFileInfo(name string) os.FileInfo { |
||||
return &bindataFileInfo{ |
||||
name: name, |
||||
size: 0, |
||||
mode: os.FileMode(2147484068), // equal os.FileMode(0644)|os.ModeDir
|
||||
modTime: time.Time{}} |
||||
} |
||||
|
||||
// AssetFile return a http.FileSystem instance that data backend by asset
|
||||
func AssetFile() http.FileSystem { |
||||
return &assetOperator{} |
||||
} |
||||
|
||||
`) |
||||
return err |
||||
} |
@ -0,0 +1 @@
|
||||
go-bindata |
@ -0,0 +1,33 @@
|
||||
FILES:=$(wildcard out/*.go)
|
||||
|
||||
.PHONY: check |
||||
check: errcheck golint $(FILES:.go=.checked) |
||||
|
||||
out/%.checked: out/%.go |
||||
errcheck $<
|
||||
go vet --all $<
|
||||
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
|
||||
|
||||
golint: |
||||
go get golang.org/x/lint/golint
|
@ -0,0 +1 @@
|
||||
// sample file |
@ -0,0 +1 @@
|
||||
// sample file |
@ -0,0 +1 @@
|
||||
// sample file |
@ -0,0 +1 @@
|
||||
// sample file |
@ -0,0 +1 @@
|
||||
// sample file |
@ -0,0 +1 @@
|
||||
// sample file |
@ -0,0 +1,311 @@
|
||||
// Code generated for package main by go-bindata DO NOT EDIT.
|
||||
// sources:
|
||||
// in/a/test.asset
|
||||
// in/b/test.asset
|
||||
// in/c/test.asset
|
||||
// in/test.asset
|
||||
|
||||
package main |
||||
|
||||
import ( |
||||
"bytes" |
||||
"compress/gzip" |
||||
"fmt" |
||||
"io" |
||||
"io/ioutil" |
||||
"os" |
||||
"path/filepath" |
||||
"strings" |
||||
"time" |
||||
) |
||||
|
||||
func bindataRead(data []byte, name string) ([]byte, error) { |
||||
gz, err := gzip.NewReader(bytes.NewBuffer(data)) |
||||
if err != nil { |
||||
return nil, fmt.Errorf("Read %q: %v", name, err) |
||||
} |
||||
|
||||
var buf bytes.Buffer |
||||
_, err = io.Copy(&buf, gz) |
||||
clErr := gz.Close() |
||||
|
||||
if err != nil { |
||||
return nil, fmt.Errorf("Read %q: %v", name, err) |
||||
} |
||||
if clErr != nil { |
||||
return nil, err |
||||
} |
||||
|
||||
return buf.Bytes(), nil |
||||
} |
||||
|
||||
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 |
||||
} |
||||
|
||||
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", |
||||
) |
||||
} |
||||
|
||||
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("\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", |
||||
) |
||||
} |
||||
|
||||
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.
|
||||
// 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": inATestAsset, |
||||
"in/b/test.asset": inBTestAsset, |
||||
"in/c/test.asset": inCTestAsset, |
||||
"in/test.asset": inTestAsset, |
||||
} |
||||
|
||||
// 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, "/")...)...) |
||||
} |
@ -0,0 +1,311 @@
|
||||
// Code generated for package main by go-bindata DO NOT EDIT.
|
||||
// sources:
|
||||
// in/a/test.asset
|
||||
// in/b/test.asset
|
||||
// in/c/test.asset
|
||||
// in/test.asset
|
||||
|
||||
package main |
||||
|
||||
import ( |
||||
"bytes" |
||||
"compress/gzip" |
||||
"fmt" |
||||
"io" |
||||
"io/ioutil" |
||||
"os" |
||||
"path/filepath" |
||||
"strings" |
||||
"time" |
||||
) |
||||
|
||||
func bindataRead(data, name string) ([]byte, error) { |
||||
gz, err := gzip.NewReader(strings.NewReader(data)) |
||||
if err != nil { |
||||
return nil, fmt.Errorf("Read %q: %v", name, err) |
||||
} |
||||
|
||||
var buf bytes.Buffer |
||||
_, err = io.Copy(&buf, gz) |
||||
clErr := gz.Close() |
||||
|
||||
if err != nil { |
||||
return nil, fmt.Errorf("Read %q: %v", name, err) |
||||
} |
||||
if clErr != nil { |
||||
return nil, err |
||||
} |
||||
|
||||
return buf.Bytes(), nil |
||||
} |
||||
|
||||
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 |
||||
} |
||||
|
||||
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", |
||||
) |
||||
} |
||||
|
||||
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 = "\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", |
||||
) |
||||
} |
||||
|
||||
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.
|
||||
// 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": inATestAsset, |
||||
"in/b/test.asset": inBTestAsset, |
||||
"in/c/test.asset": inCTestAsset, |
||||
"in/test.asset": inTestAsset, |
||||
} |
||||
|
||||
// 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, "/")...)...) |
||||
} |
@ -0,0 +1,262 @@
|
||||
// Code generated for package main by go-bindata DO NOT EDIT.
|
||||
// sources:
|
||||
// in/a/test.asset
|
||||
// in/b/test.asset
|
||||
// in/c/test.asset
|
||||
// in/test.asset
|
||||
|
||||
package main |
||||
|
||||
import ( |
||||
"fmt" |
||||
"io/ioutil" |
||||
"os" |
||||
"path/filepath" |
||||
"strings" |
||||
) |
||||
|
||||
// bindataRead reads the given file from disk. It returns an error on failure.
|
||||
func bindataRead(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 |
||||
} |
||||
|
||||
// inATestAsset reads file data from disk. It returns an error on failure.
|
||||
func inATestAsset() (*asset, error) { |
||||
path := "/home/ts/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/a/test.asset" |
||||
name := "in/a/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 |
||||
} |
||||
|
||||
// inBTestAsset reads file data from disk. It returns an error on failure.
|
||||
func inBTestAsset() (*asset, error) { |
||||
path := "/home/ts/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/b/test.asset" |
||||
name := "in/b/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 |
||||
} |
||||
|
||||
// inCTestAsset reads file data from disk. It returns an error on failure.
|
||||
func inCTestAsset() (*asset, error) { |
||||
path := "/home/ts/code/go/src/github.com/jteeuwen/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/github.com/jteeuwen/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.
|
||||
// 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": inATestAsset, |
||||
"in/b/test.asset": inBTestAsset, |
||||
"in/c/test.asset": inCTestAsset, |
||||
"in/test.asset": inTestAsset, |
||||
} |
||||
|
||||
// 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, "/")...)...) |
||||
} |
@ -0,0 +1,259 @@
|
||||
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/github.com/jteeuwen/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/github.com/jteeuwen/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/github.com/jteeuwen/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/github.com/jteeuwen/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, "/")...)...) |
||||
} |
||||
|
@ -0,0 +1,280 @@
|
||||
// Code generated for package main by go-bindata DO NOT EDIT.
|
||||
// sources:
|
||||
// in/a/test.asset
|
||||
// in/b/test.asset
|
||||
// in/c/test.asset
|
||||
// in/test.asset
|
||||
|
||||
package main |
||||
|
||||
import ( |
||||
"fmt" |
||||
"io/ioutil" |
||||
"os" |
||||
"path/filepath" |
||||
"strings" |
||||
"time" |
||||
) |
||||
|
||||
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 |
||||
} |
||||
|
||||
var _inATestAsset = []byte(`// sample file
|
||||
`) |
||||
|
||||
func inATestAssetBytes() ([]byte, error) { |
||||
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.
|
||||
// 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": inATestAsset, |
||||
"in/b/test.asset": inBTestAsset, |
||||
"in/c/test.asset": inCTestAsset, |
||||
"in/test.asset": inTestAsset, |
||||
} |
||||
|
||||
// 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, "/")...)...) |
||||
} |
@ -0,0 +1,301 @@
|
||||
// Code generated by go-bindata DO NOT EDIT.
|
||||
// sources:
|
||||
// in/a/test.asset
|
||||
// in/b/test.asset
|
||||
// in/c/test.asset
|
||||
// in/test.asset
|
||||
|
||||
package main |
||||
|
||||
import ( |
||||
"fmt" |
||||
"io/ioutil" |
||||
"os" |
||||
"path/filepath" |
||||
"reflect" |
||||
"strings" |
||||
"time" |
||||
"unsafe" |
||||
) |
||||
|
||||
func bindataRead(data, name string) ([]byte, error) { |
||||
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, nil |
||||
} |
||||
|
||||
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 |
||||
} |
||||
|
||||
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", |
||||
) |
||||
} |
||||
|
||||
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 = "\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", |
||||
) |
||||
} |
||||
|
||||
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.
|
||||
// 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": inATestAsset, |
||||
"in/b/test.asset": inBTestAsset, |
||||
"in/c/test.asset": inCTestAsset, |
||||
"in/test.asset": inTestAsset, |
||||
} |
||||
|
||||
// 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, "/")...)...) |
||||
} |
@ -0,0 +1 @@
|
||||
../symlinkSrc/file1 |
@ -0,0 +1 @@
|
||||
../symlinkSrc/ |
@ -0,0 +1 @@
|
||||
// test file 1 |
@ -0,0 +1 @@
|
||||
../symlinkRecursiveParent/ |
@ -0,0 +1 @@
|
||||
// symlink file 1 |
@ -0,0 +1 @@
|
||||
// symlink file 2 |
@ -0,0 +1 @@
|
||||
// symlink file 3 |
@ -0,0 +1 @@
|
||||
// symlink file 4 |
Loading…
Reference in new issue