From b7408963591dd7affadcd1d01928ff04a88f60a6 Mon Sep 17 00:00:00 2001 From: "A. Svensson" Date: Tue, 3 May 2016 18:47:15 +0200 Subject: [PATCH] Update template assets. --- src/assettemplates/asset_build.go | 58 +++++++++++++++---------------- src/assettemplates/asset_dev.go | 49 +++++++++++++++++--------- 2 files changed, 61 insertions(+), 46 deletions(-) diff --git a/src/assettemplates/asset_build.go b/src/assettemplates/asset_build.go index 4977aff..125800e 100644 --- a/src/assettemplates/asset_build.go +++ b/src/assettemplates/asset_build.go @@ -1,48 +1,48 @@ // +build embed -// Automagically generated by yaber v0.1 (https://github.com/lmas/yaber), +// Automagically generated by yaber v0.2 (https://github.com/lmas/yaber), // please avoid editting this file as it might be regenerated again. package assettemplates import ( - "bytes" - "compress/gzip" - "io/ioutil" - "os" - "strings" + "bytes" + "compress/gzip" + "io/ioutil" + "os" + "strings" ) func Asset(path string) ([]byte, error) { - body, ok := _rawAssets[path] - if !ok { - return nil, os.ErrNotExist - } - return decompress(body) + body, ok := _rawAssets[path] + if !ok { + return nil, os.ErrNotExist + } + return decompress(body) } func AssetDir(dir string) (map[string][]byte, error) { - var e error - files := make(map[string][]byte) - for path, body := range _rawAssets { - if strings.HasPrefix(path, dir) { - files[path], e = decompress(body) - if e != nil { - return nil, e - } - } - } - return files, nil + var e error + files := make(map[string][]byte) + for path, body := range _rawAssets { + if strings.HasPrefix(path, dir) { + files[path], e = decompress(body) + if e != nil { + return nil, e + } + } + } + return files, nil } func decompress(data []byte) ([]byte, error) { - buf := bytes.NewBuffer(data) - gr, e := gzip.NewReader(buf) - if e != nil { - return nil, e - } - defer gr.Close() - return ioutil.ReadAll(gr) + buf := bytes.NewBuffer(data) + gr, e := gzip.NewReader(buf) + if e != nil { + return nil, e + } + defer gr.Close() + return ioutil.ReadAll(gr) } var _rawAssets = map[string][]byte{ diff --git a/src/assettemplates/asset_dev.go b/src/assettemplates/asset_dev.go index b019408..3a3c75c 100644 --- a/src/assettemplates/asset_dev.go +++ b/src/assettemplates/asset_dev.go @@ -1,13 +1,13 @@ // +build !embed -// Automagically generated by yaber v0.1 (https://github.com/lmas/yaber), +// Automagically generated by yaber v0.2 (https://github.com/lmas/yaber), // please avoid editting this file as it might be regenerated again. package assettemplates import ( - "io/ioutil" - "path/filepath" + "io/ioutil" + "path/filepath" ) func Asset(path string) ([]byte, error) { @@ -15,19 +15,34 @@ func Asset(path string) ([]byte, error) { } func AssetDir(dir string) (map[string][]byte, error) { - tmp, e := ioutil.ReadDir(dir) - if e != nil { - return nil, e - } + list := make(map[string][]byte) + dirs := []string{dir} - files := make(map[string][]byte) - for _, f := range tmp { - name := filepath.Join(dir, f.Name()) - body, e := ioutil.ReadFile(name) - if e != nil { - return nil, e - } - files[name] = body - } - return files, nil + for len(dirs) > 0 { + d := dirs[0] + dirs = dirs[1:] + files, e := ioutil.ReadDir(d) + if e != nil { + return nil, e + } + + for _, f := range files { + fpath := filepath.Join(d, f.Name()) + + if f.IsDir() { + dirs = append(dirs, fpath) + continue + } + if !f.Mode().IsRegular() { + continue + } + + fbody, e := ioutil.ReadFile(fpath) + if e != nil { + return nil, e + } + list[fpath] = fbody + } + } + return list, nil }