bump(github.com/elazarl/go-bindata-assetfs): 3dcc96556217539f50599357fb481ac0dc7439b9

This commit is contained in:
Jordan Liggitt 2015-09-10 16:59:19 -04:00
parent 28585bc699
commit b546045c44
3 changed files with 43 additions and 8 deletions

2
Godeps/Godeps.json generated
View File

@ -211,7 +211,7 @@
},
{
"ImportPath": "github.com/elazarl/go-bindata-assetfs",
"Rev": "c57a80f1ab2ad67bafa83f5fd0b4c2ecbd253dd5"
"Rev": "3dcc96556217539f50599357fb481ac0dc7439b9"
},
{
"ImportPath": "github.com/emicklei/go-restful",

View File

@ -136,12 +136,12 @@ func (fs *AssetFS) Open(name string) (http.File, error) {
if len(name) > 0 && name[0] == '/' {
name = name[1:]
}
if b, err := fs.Asset(name); err == nil {
return NewAssetFile(name, b), nil
}
if children, err := fs.AssetDir(name); err == nil {
return NewAssetDirectory(name, children, fs), nil
}
b, err := fs.Asset(name)
if err != nil {
} else {
return nil, err
}
return NewAssetFile(name, b), nil
}

View File

@ -3,13 +3,31 @@ package main
import (
"bufio"
"bytes"
"flag"
"fmt"
"os"
"os/exec"
"strings"
)
const bindatafile = "bindata.go"
func isDebug(args []string) bool {
flagset := flag.NewFlagSet("", flag.ContinueOnError)
debug := flagset.Bool("debug", false, "")
debugArgs := make([]string, 0)
for _, arg := range args {
if strings.HasPrefix(arg, "-debug") {
debugArgs = append(debugArgs, arg)
}
}
flagset.Parse(debugArgs)
if debug == nil {
return false
}
return *debug
}
func main() {
if _, err := exec.LookPath("go-bindata"); err != nil {
fmt.Println("Cannot find go-bindata executable in path")
@ -33,26 +51,43 @@ func main() {
fmt.Fprintln(os.Stderr, "Cannot write 'bindata_assetfs.go'", err)
return
}
debug := isDebug(os.Args[1:])
r := bufio.NewReader(in)
done := false
for line, isPrefix, err := r.ReadLine(); err == nil; line, isPrefix, err = r.ReadLine() {
line = append(line, '\n')
if !isPrefix {
line = append(line, '\n')
}
if _, err := out.Write(line); err != nil {
fmt.Fprintln(os.Stderr, "Cannot write to 'bindata_assetfs.go'", err)
return
}
if !done && !isPrefix && bytes.HasPrefix(line, []byte("import (")) {
fmt.Fprintln(out, "\t\"github.com/elazarl/go-bindata-assetfs\"")
if debug {
fmt.Fprintln(out, "\t\"net/http\"")
} else {
fmt.Fprintln(out, "\t\"github.com/elazarl/go-bindata-assetfs\"")
}
done = true
}
}
fmt.Fprintln(out, `
if debug {
fmt.Fprintln(out, `
func assetFS() http.FileSystem {
for k := range _bintree.Children {
return http.Dir(k)
}
panic("unreachable")
}`)
} else {
fmt.Fprintln(out, `
func assetFS() *assetfs.AssetFS {
for k := range _bintree.Children {
return &assetfs.AssetFS{Asset: Asset, AssetDir: AssetDir, Prefix: k}
}
panic("unreachable")
}`)
}
// Close files BEFORE remove calls (don't use defer).
in.Close()
out.Close()