Merge pull request #43 from Byron/master

AssetDir is now able to list the data root.
This commit is contained in:
jimt 2014-08-07 16:44:26 +02:00
commit 64e31e0c92

15
toc.go
View File

@ -90,14 +90,17 @@ func writeTOCTree(w io.Writer, toc []Asset) error {
// then AssetDir("data") would return []string{"foo.txt", "img"} // then AssetDir("data") would return []string{"foo.txt", "img"}
// AssetDir("data/img") would return []string{"a.png", "b.png"} // AssetDir("data/img") would return []string{"a.png", "b.png"}
// AssetDir("foo.txt") and AssetDir("notexist") would return an error // AssetDir("foo.txt") and AssetDir("notexist") would return an error
// AssetDir("") will return []string{"data"}.
func AssetDir(name string) ([]string, error) { func AssetDir(name string) ([]string, error) {
cannonicalName := strings.Replace(name, "\\", "/", -1)
pathList := strings.Split(cannonicalName, "/")
node := _bintree node := _bintree
for _, p := range pathList { if len(name) != 0 {
node = node.Children[p] cannonicalName := strings.Replace(name, "\\", "/", -1)
if node == nil { pathList := strings.Split(cannonicalName, "/")
return nil, fmt.Errorf("Asset %%s not found", name) for _, p := range pathList {
node = node.Children[p]
if node == nil {
return nil, fmt.Errorf("Asset %%s not found", name)
}
} }
} }
if node.Func != nil { if node.Func != nil {