AssetDir is now able to list the data root.

Previously, it was impossible to get a listing of entries right underneath
the data root.

Such a query is now possible by passing an empty string as data root.
This commit is contained in:
Sebastian Thiel 2014-08-07 16:24:25 +02:00
parent 388b47b5ff
commit 6ca6b73691

5
toc.go
View File

@ -90,16 +90,19 @@ 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) {
node := _bintree
if len(name) != 0 {
cannonicalName := strings.Replace(name, "\\", "/", -1) cannonicalName := strings.Replace(name, "\\", "/", -1)
pathList := strings.Split(cannonicalName, "/") pathList := strings.Split(cannonicalName, "/")
node := _bintree
for _, p := range pathList { for _, p := range pathList {
node = node.Children[p] node = node.Children[p]
if node == nil { if node == nil {
return nil, fmt.Errorf("Asset %%s not found", name) return nil, fmt.Errorf("Asset %%s not found", name)
} }
} }
}
if node.Func != nil { if node.Func != nil {
return nil, fmt.Errorf("Asset %%s not found", name) return nil, fmt.Errorf("Asset %%s not found", name)
} }