From 665944b4445ae32eac66f4812297dff2b364add3 Mon Sep 17 00:00:00 2001 From: jim teeuwen Date: Thu, 7 Jun 2012 23:28:16 +0200 Subject: [PATCH] Remove some unneccesary code bits. --- bindata.go | 6 ++--- main.go | 67 +++++++++++++++++++++++++----------------------------- 2 files changed, 33 insertions(+), 40 deletions(-) diff --git a/bindata.go b/bindata.go index 45fa705..440b3be 100644 --- a/bindata.go +++ b/bindata.go @@ -12,16 +12,15 @@ import ( // Translate the input file without GZIP compression. // input -> gowriter -> output. -func translate_uncompressed(input io.Reader, output io.Writer, pkgname, funcname string) (err error) { +func translate_uncompressed(input io.Reader, output io.Writer, pkgname, funcname string) { fmt.Fprintf(output, "package %s\n\nvar %s []byte = []byte{", pkgname, funcname) io.Copy(&GoWriter{Writer: output}, input) fmt.Fprint(output, "\n}") - return } // Translate the input file with GZIP compression. // input -> gzip -> gowriter -> output. -func translate_compressed(input io.Reader, output io.Writer, pkgname, funcname string) (err error) { +func translate_compressed(input io.Reader, output io.Writer, pkgname, funcname string) { fmt.Fprintf(output, `package %s import ( @@ -52,5 +51,4 @@ func %s() []byte { return b.Bytes() }`) - return } diff --git a/main.go b/main.go index 1243080..6254bf2 100644 --- a/main.go +++ b/main.go @@ -16,7 +16,7 @@ import ( const ( AppName = "bindata" - AppVersion = "0.6" + AppVersion = "0.7" ) func main() { @@ -81,57 +81,52 @@ func main() { file = strings.Replace(file, " ", "_", -1) file = strings.Replace(file, ".", "_", -1) file = strings.Replace(file, "-", "_", -1) + if unicode.IsDigit(rune(file[0])) { // Identifier can't start with a digit. file = "_" + file } + fmt.Fprintf(os.Stderr, "[w] No function name specified. Using '%s'.\n", file) *funcname = file } } - var err error - // Read the input file, transform it into a gzip compressed data stream and // write it out as a go source file. if pipe { if *uncompressed { - err = translate_uncompressed(os.Stdin, os.Stdout, *pkgname, *funcname) + translate_uncompressed(os.Stdin, os.Stdout, *pkgname, *funcname) } else { - err = translate_compressed(os.Stdin, os.Stdout, *pkgname, *funcname) - } - - if err != nil { - fmt.Fprintf(os.Stderr, "[e] %s\n", err) - } - } else { - var fs, fd *os.File - - if fs, err = os.Open(*in); err != nil { - fmt.Fprintf(os.Stderr, "[e] %s\n", err) - return - } - - defer fs.Close() - - if fd, err = os.Create(*out); err != nil { - fmt.Fprintf(os.Stderr, "[e] %s\n", err) - return - } - - defer fd.Close() - - if *uncompressed { - err = translate_uncompressed(fs, fd, *pkgname, *funcname) - } else { - err = translate_compressed(fs, fd, *pkgname, *funcname) - } - - if err != nil { - fmt.Fprintf(os.Stderr, "[e] %s\n", err) - return + translate_compressed(os.Stdin, os.Stdout, *pkgname, *funcname) } fmt.Fprintln(os.Stdout, "[i] Done.") + return } + + var fs, fd *os.File + var err error + + if fs, err = os.Open(*in); err != nil { + fmt.Fprintf(os.Stderr, "[e] %s\n", err) + return + } + + defer fs.Close() + + if fd, err = os.Create(*out); err != nil { + fmt.Fprintf(os.Stderr, "[e] %s\n", err) + return + } + + defer fd.Close() + + if *uncompressed { + translate_uncompressed(fs, fd, *pkgname, *funcname) + } else { + translate_compressed(fs, fd, *pkgname, *funcname) + } + + fmt.Fprintln(os.Stdout, "[i] Done.") }