Imported Upstream version 3.0.5
Vincent Bernat
10 years ago
6 | 6 |
It comes with a command line tool in the `go-bindata` sub directory.
|
7 | 7 |
This tool offers a set of command line options, used to customize the
|
8 | 8 |
output being generated.
|
|
9 |
|
|
10 |
|
|
11 |
### Installation
|
|
12 |
|
|
13 |
To install the library and command line program, use the following:
|
|
14 |
|
|
15 |
go get github.com/jteeuwen/go-bindata/...
|
9 | 16 |
|
10 | 17 |
|
11 | 18 |
### Usage
|
|
31 | 38 |
|
32 | 39 |
Multiple input directories can be specified if necessary.
|
33 | 40 |
|
34 | |
$ go-bindata dir1/... /path/to/dir3/... dir3
|
|
41 |
$ go-bindata dir1/... /path/to/dir2/... dir3
|
35 | 42 |
|
36 | 43 |
|
37 | 44 |
The following paragraphs detail some of the command line options which can
|
38 | 45 |
supplied to `go-bindata`. Refer to the `testdata/out` directory for various
|
39 | 46 |
output examples from the assets in `testdata/in`. Each example uses different
|
40 | 47 |
command line options.
|
|
48 |
|
|
49 |
|
|
50 |
### Accessing an asset
|
|
51 |
|
|
52 |
To access asset data, we use the `Asset(string) []byte` function which
|
|
53 |
is included in the generated output.
|
|
54 |
|
|
55 |
data := Asset("pub/style/foo.css")
|
|
56 |
if len(data) == 0 {
|
|
57 |
// Asset was not found.
|
|
58 |
}
|
|
59 |
|
|
60 |
// use asset data
|
41 | 61 |
|
42 | 62 |
|
43 | 63 |
### Debug vs Release builds
|
4 | 4 |
package bindata
|
5 | 5 |
|
6 | 6 |
import (
|
|
7 |
"bufio"
|
7 | 8 |
"fmt"
|
8 | 9 |
"os"
|
9 | 10 |
"path/filepath"
|
|
40 | 41 |
|
41 | 42 |
defer fd.Close()
|
42 | 43 |
|
|
44 |
// Create a buffered writer for better performance.
|
|
45 |
bfd := bufio.NewWriter(fd)
|
|
46 |
defer bfd.Flush()
|
|
47 |
|
43 | 48 |
// Write build tags, if applicable.
|
44 | 49 |
if len(c.Tags) > 0 {
|
45 | |
_, err = fmt.Fprintf(fd, "// +build %s\n\n", c.Tags)
|
|
50 |
_, err = fmt.Fprintf(bfd, "// +build %s\n\n", c.Tags)
|
46 | 51 |
if err != nil {
|
47 | 52 |
return err
|
48 | 53 |
}
|
49 | 54 |
}
|
50 | 55 |
|
51 | 56 |
// Write package declaration.
|
52 | |
_, err = fmt.Fprintf(fd, "package %s\n\n", c.Package)
|
|
57 |
_, err = fmt.Fprintf(bfd, "package %s\n\n", c.Package)
|
53 | 58 |
if err != nil {
|
54 | 59 |
return err
|
55 | 60 |
}
|
56 | 61 |
|
57 | 62 |
// Write assets.
|
58 | 63 |
if c.Debug {
|
59 | |
err = writeDebug(fd, toc)
|
|
64 |
err = writeDebug(bfd, toc)
|
60 | 65 |
} else {
|
61 | |
err = writeRelease(fd, c, toc)
|
|
66 |
err = writeRelease(bfd, c, toc)
|
62 | 67 |
}
|
63 | 68 |
|
64 | 69 |
if err != nil {
|
|
66 | 71 |
}
|
67 | 72 |
|
68 | 73 |
// Write table of contents
|
69 | |
return writeTOC(fd, toc)
|
|
74 |
return writeTOC(bfd, toc)
|
70 | 75 |
}
|
71 | 76 |
|
72 | 77 |
// findFiles recursively finds all the file paths in the given directory tree.
|
4 | 4 |
package bindata
|
5 | 5 |
|
6 | 6 |
import (
|
7 | |
"fmt"
|
8 | 7 |
"io"
|
9 | 8 |
)
|
|
9 |
|
|
10 |
const lowerHex = "0123456789abcdef"
|
10 | 11 |
|
11 | 12 |
type StringWriter struct {
|
12 | 13 |
io.Writer
|
|
18 | 19 |
return
|
19 | 20 |
}
|
20 | 21 |
|
21 | |
for n = range p {
|
22 | |
fmt.Fprintf(w.Writer, "\\x%02x", p[n])
|
|
22 |
buf := []byte(`\x00`)
|
|
23 |
var b byte
|
|
24 |
|
|
25 |
for n, b = range p {
|
|
26 |
buf[2] = lowerHex[b/16]
|
|
27 |
buf[3] = lowerHex[b%16]
|
|
28 |
w.Writer.Write(buf)
|
23 | 29 |
w.c++
|
24 | 30 |
}
|
25 | 31 |
|