Made the code usable as a library

- Library is named bindata
- Currently exports: Translate
- The library code is in lib/
This commit is contained in:
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: // license. Its contents can be found at:
// http://creativecommons.org/publicdomain/zero/1.0/ // http://creativecommons.org/publicdomain/zero/1.0/
package main package bindata
import ( import (
"fmt" "fmt"

View File

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

View File

@ -2,7 +2,7 @@
// license. Its contents can be found at: // license. Its contents can be found at:
// http://creativecommons.org/publicdomain/zero/1.0/ // http://creativecommons.org/publicdomain/zero/1.0/
package main package bindata
import ( import (
"fmt" "fmt"
@ -13,7 +13,7 @@ import (
) )
// createTOC writes a table of contents file to the given location. // 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") file := filepath.Join(dir, "bindata-toc.go")
code := fmt.Sprintf(`package %s 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. // 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) filename = strings.Replace(filename, prefix, "", 1)
fmt.Fprintf(output, ` fmt.Fprintf(output, `

View File

@ -2,7 +2,7 @@
// license. Its contents can be found at: // license. Its contents can be found at:
// http://creativecommons.org/publicdomain/zero/1.0/ // http://creativecommons.org/publicdomain/zero/1.0/
package main package bindata
import ( import (
"compress/gzip" "compress/gzip"
@ -11,7 +11,7 @@ import (
) )
// translate translates the input file to go source code. // 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 nomemcpy {
if uncompressed { if uncompressed {
translate_nomemcpy_uncomp(input, output, pkgname, funcname) translate_nomemcpy_uncomp(input, output, pkgname, funcname)

View File

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

11
main.go
View File

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