Fix generate doutput code. os.Error -> error. Remove calling of go fmt from code. This should really be done manually.
This commit is contained in:
parent
2b9a31984c
commit
02da4740e4
|
@ -1,23 +1,10 @@
|
||||||
================================================================================
|
## Bindata
|
||||||
bindata
|
|
||||||
================================================================================
|
|
||||||
|
|
||||||
This tool converts any file into managable Go source code. Useful for embedding
|
This tool converts any file into managable Go source code. Useful for embedding
|
||||||
binary data into a go program. The file data is gzip compressed before being
|
binary data into a go program. The file data is gzip compressed before being
|
||||||
converted to a raw byte slice.
|
converted to a raw byte slice.
|
||||||
|
|
||||||
If gofmt is available on the system, bindata will invoke it to format the
|
### USAGE
|
||||||
generated go file.
|
|
||||||
|
|
||||||
================================================================================
|
|
||||||
DEPENDENCIES
|
|
||||||
================================================================================
|
|
||||||
|
|
||||||
n/a
|
|
||||||
|
|
||||||
================================================================================
|
|
||||||
USAGE
|
|
||||||
================================================================================
|
|
||||||
|
|
||||||
The simplest invocation is to pass it only the input file name.
|
The simplest invocation is to pass it only the input file name.
|
||||||
The output file and code settings are inferred from this automatically.
|
The output file and code settings are inferred from this automatically.
|
47
bindata.go
47
bindata.go
|
@ -8,36 +8,25 @@ import (
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"path"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// If gofmt exists on the system, run it over the target file to
|
|
||||||
// fix up the generated code. This is not necessary, just a convenience.
|
|
||||||
func gofmt(file string) (err error) {
|
|
||||||
var prog string
|
|
||||||
if prog = os.Getenv("GOBIN"); len(prog) == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
prog = path.Join(prog, "gofmt")
|
|
||||||
cmd := exec.Command(prog, "-w", file)
|
|
||||||
return cmd.Run()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Translate the input file.
|
// Translate the input file.
|
||||||
// input -> gzip -> gowriter -> output.
|
// input -> gzip -> gowriter -> output.
|
||||||
func translate(input io.Reader, output io.Writer, pkgname, funcname string) (err error) {
|
func translate(input io.Reader, output io.Writer, pkgname, funcname string) (err error) {
|
||||||
var gz *gzip.Compressor
|
var gz *gzip.Compressor
|
||||||
|
|
||||||
fmt.Fprintf(output, `package %s
|
fmt.Fprintf(output, `package %s
|
||||||
import ( "io"; "os"; "bytes"; "compress/gzip" )
|
|
||||||
|
|
||||||
func %s() ([]byte, os.Error) {
|
import (
|
||||||
var gz *gzip.Decompressor
|
"bytes"
|
||||||
var err os.Error
|
"compress/gzip"
|
||||||
if gz, err = gzip.NewReader(bytes.NewBuffer([]byte{`, pkgname, funcname)
|
"io"
|
||||||
|
)
|
||||||
|
|
||||||
|
func %s() ([]byte, error) {
|
||||||
|
var gz *gzip.Decompressor
|
||||||
|
var err error
|
||||||
|
if gz, err = gzip.NewReader(bytes.NewBuffer([]byte{`, pkgname, funcname)
|
||||||
|
|
||||||
if gz, err = gzip.NewWriter(&GoWriter{Writer: output}); err != nil {
|
if gz, err = gzip.NewWriter(&GoWriter{Writer: output}); err != nil {
|
||||||
return
|
return
|
||||||
|
@ -47,13 +36,15 @@ if gz, err = gzip.NewReader(bytes.NewBuffer([]byte{`, pkgname, funcname)
|
||||||
gz.Close()
|
gz.Close()
|
||||||
|
|
||||||
fmt.Fprint(output, `
|
fmt.Fprint(output, `
|
||||||
})); err != nil {
|
})); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
io.Copy(&b, gz)
|
io.Copy(&b, gz)
|
||||||
gz.Close()
|
gz.Close()
|
||||||
return b.Bytes(), nil}`)
|
|
||||||
|
return b.Bytes(), nil
|
||||||
|
}`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
11
main.go
11
main.go
|
@ -16,7 +16,7 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
APP_NAME = "bindata"
|
APP_NAME = "bindata"
|
||||||
APP_VERSION = "0.4"
|
APP_VERSION = "0.5"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -89,9 +89,10 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
|
||||||
// Read the input file, transform it into a gzip compressed data stream and
|
// Read the input file, transform it into a gzip compressed data stream and
|
||||||
// write it out as a go source file.
|
// write it out as a go source file.
|
||||||
var err error
|
|
||||||
if pipe {
|
if pipe {
|
||||||
if err = translate(os.Stdin, os.Stdout, *pkgname, *funcname); err != nil {
|
if err = translate(os.Stdin, os.Stdout, *pkgname, *funcname); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "[e] %s\n", err)
|
fmt.Fprintf(os.Stderr, "[e] %s\n", err)
|
||||||
|
@ -118,12 +119,6 @@ func main() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// If gofmt exists on the system, use it to format the generated source file.
|
|
||||||
if err = gofmt(*out); err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "[e] %s\n", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
fmt.Fprintln(os.Stdout, "[i] Done.")
|
fmt.Fprintln(os.Stdout, "[i] Done.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
3653
testdata/gophercolor.png.go
vendored
3653
testdata/gophercolor.png.go
vendored
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user