Made the code usable as a library

- Library is named bindata
- Currently exports: Translate
- The library code is in lib/
pull/4/head
Pierre Baillet 2013-09-30 20:46:15 +02:00
parent 6fb0150f0c
commit e6d1b0ecbd
7 changed files with 14 additions and 13 deletions

BIN
binary/binary Executable file

Binary file not shown.

View File

@ -2,7 +2,7 @@
// license. Its contents can be found at:
// http://creativecommons.org/publicdomain/zero/1.0/
package main
package bindata
import (
"fmt"

View File

@ -2,7 +2,7 @@
// license. Its contents can be found at:
// http://creativecommons.org/publicdomain/zero/1.0/
package main
package bindata
import (
"fmt"

View File

@ -2,7 +2,7 @@
// license. Its contents can be found at:
// http://creativecommons.org/publicdomain/zero/1.0/
package main
package bindata
import (
"fmt"
@ -13,7 +13,7 @@ import (
)
// createTOC writes a table of contents file to the given location.
func createTOC(dir, pkgname string) error {
func CreateTOC(dir, pkgname string) error {
file := filepath.Join(dir, "bindata-toc.go")
code := fmt.Sprintf(`package %s
@ -27,7 +27,7 @@ var go_bindata = make(map[string]func() []byte)`, pkgname)
}
// writeTOCInit writes the TOC init function for a given data file.
func writeTOCInit(output io.Writer, filename, prefix, funcname string) {
func WriteTOCInit(output io.Writer, filename, prefix, funcname string) {
filename = strings.Replace(filename, prefix, "", 1)
fmt.Fprintf(output, `

View File

@ -2,7 +2,7 @@
// license. Its contents can be found at:
// http://creativecommons.org/publicdomain/zero/1.0/
package main
package bindata
import (
"compress/gzip"
@ -11,7 +11,7 @@ import (
)
// translate translates the input file to go source code.
func translate(input io.Reader, output io.Writer, pkgname, funcname string, uncompressed, nomemcpy bool) {
func Translate(input io.Reader, output io.Writer, pkgname, funcname string, uncompressed, nomemcpy bool) {
if nomemcpy {
if uncompressed {
translate_nomemcpy_uncomp(input, output, pkgname, funcname)

View File

@ -2,7 +2,7 @@
// license. Its contents can be found at:
// http://creativecommons.org/publicdomain/zero/1.0/
package main
package bindata
import (
"fmt"

11
main.go
View File

@ -7,6 +7,7 @@ package main
import (
"flag"
"fmt"
"github.com/jteeuwen/go-bindata/lib"
"os"
"path"
"path/filepath"
@ -34,7 +35,7 @@ func main() {
parseArgs()
if pipe {
translate(os.Stdin, os.Stdout, *pkgname, *funcname, *uncompressed, *nomemcopy)
bindata.Translate(os.Stdin, os.Stdout, *pkgname, *funcname, *uncompressed, *nomemcopy)
return
}
@ -59,20 +60,20 @@ func main() {
}
// Translate binary to Go code.
translate(fs, fd, *pkgname, *funcname, *uncompressed, *nomemcopy)
bindata.Translate(fs, fd, *pkgname, *funcname, *uncompressed, *nomemcopy)
// Append the TOC init function to the end of the output file and
// write the `bindata-toc.go` file, if applicable.
if *toc {
dir, _ := filepath.Split(*out)
err := createTOC(dir, *pkgname)
err := bindata.CreateTOC(dir, *pkgname)
if err != nil {
fmt.Fprintf(os.Stderr, "[e] %s\n", err)
return
}
writeTOCInit(fd, in, *prefix, *funcname)
bindata.WriteTOCInit(fd, in, *prefix, *funcname)
}
}
@ -85,7 +86,7 @@ func parseArgs() {
flag.Parse()
if *version {
fmt.Printf("%s\n", Version())
fmt.Printf("%s\n", bindata.Version())
os.Exit(0)
}