Codebase list golang-bindata / 77dd0ab
Imported Upstream version 3.0.5 Vincent Bernat 10 years ago
3 changed file(s) with 40 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
66 It comes with a command line tool in the `go-bindata` sub directory.
77 This tool offers a set of command line options, used to customize the
88 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/...
916
1017
1118 ### Usage
3138
3239 Multiple input directories can be specified if necessary.
3340
34 $ go-bindata dir1/... /path/to/dir3/... dir3
41 $ go-bindata dir1/... /path/to/dir2/... dir3
3542
3643
3744 The following paragraphs detail some of the command line options which can
3845 supplied to `go-bindata`. Refer to the `testdata/out` directory for various
3946 output examples from the assets in `testdata/in`. Each example uses different
4047 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
4161
4262
4363 ### Debug vs Release builds
44 package bindata
55
66 import (
7 "bufio"
78 "fmt"
89 "os"
910 "path/filepath"
4041
4142 defer fd.Close()
4243
44 // Create a buffered writer for better performance.
45 bfd := bufio.NewWriter(fd)
46 defer bfd.Flush()
47
4348 // Write build tags, if applicable.
4449 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)
4651 if err != nil {
4752 return err
4853 }
4954 }
5055
5156 // 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)
5358 if err != nil {
5459 return err
5560 }
5661
5762 // Write assets.
5863 if c.Debug {
59 err = writeDebug(fd, toc)
64 err = writeDebug(bfd, toc)
6065 } else {
61 err = writeRelease(fd, c, toc)
66 err = writeRelease(bfd, c, toc)
6267 }
6368
6469 if err != nil {
6671 }
6772
6873 // Write table of contents
69 return writeTOC(fd, toc)
74 return writeTOC(bfd, toc)
7075 }
7176
7277 // findFiles recursively finds all the file paths in the given directory tree.
44 package bindata
55
66 import (
7 "fmt"
87 "io"
98 )
9
10 const lowerHex = "0123456789abcdef"
1011
1112 type StringWriter struct {
1213 io.Writer
1819 return
1920 }
2021
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)
2329 w.c++
2430 }
2531