Merge branch 'batchconvert'
Conflicts: lib/toc.go lib/translate.go main.gopull/4/head v3.0.3
commit
f628643380
|
@ -0,0 +1,79 @@
|
|||
## Contribution guidelines.
|
||||
|
||||
So you wish to contribute to this project? Fantastic!
|
||||
Here are a few guidelines to help you do this in a
|
||||
streamlined fashion.
|
||||
|
||||
|
||||
## Bug reports
|
||||
|
||||
When supplying a bug report, please consider the following guidelines.
|
||||
These serve to make it easier for us to address the issue and find a solution.
|
||||
Most of these are pretty self-evident, but sometimes it is still necessary
|
||||
to reiterate them.
|
||||
|
||||
* Be clear in the way you express the problem. Use simple language and
|
||||
just enough of it to clearly define the issue. Not everyone is a native
|
||||
English speaker. And while most can handle themselves pretty well,
|
||||
it helps to stay away from more esoteric vocabulary.
|
||||
|
||||
Be patient with non-native English speakers. If their bug reports
|
||||
or comments are hard to understand, just ask for clarification.
|
||||
Do not start guessing at their meaning, as this may just lead to
|
||||
more confusion and misunderstandings.
|
||||
* Clearly define any information which is relevant to the problem.
|
||||
This includes library versions, operating system and any other
|
||||
external dependencies which may be needed.
|
||||
* Where applicable, provide a step-by-step listing of the way to
|
||||
reproduce the problem. Make sure this is the simplest possible
|
||||
way to do so. Omit any and all unneccesary steps, because they may
|
||||
just complicate our understanding of the real problem.
|
||||
If need be, create a whole new code project on your local machine,
|
||||
which specifically tries to create the problem you are running into;
|
||||
nothing more, nothing less.
|
||||
|
||||
Include this program in the bug report. It often suffices to paste
|
||||
the code in a [Gist](https://gist.github.com) or on the
|
||||
[Go playground](http://play.golang.org).
|
||||
* If possible, provide us with a listing of the steps you have already
|
||||
undertaken to solve the problem. This can save us a great deal of
|
||||
wasted time, trying out solutions you have already covered.
|
||||
|
||||
|
||||
## Pull requests
|
||||
|
||||
Bug reports are great. Supplying fixes to bugs is even better.
|
||||
When submitting a pull request, the following guidelines are
|
||||
good to keep in mind:
|
||||
|
||||
* `go fmt`: **Always** run your code through `go fmt`, before
|
||||
committing it. Code has to be readable by many different
|
||||
people. And the only way this will be as painless as possible,
|
||||
is if we all stick to the same code style.
|
||||
|
||||
Some of our projects may have automated build-servers hooked up
|
||||
to commit hooks. These will vet any submitted code and determine
|
||||
if it meets a set of properties. One of which is code formatting.
|
||||
These servers will outright deny a submission which has not been
|
||||
run through `go fmt`, even if the code itself is correct.
|
||||
|
||||
We try to maintain a zero-tolerance policy on this matter,
|
||||
because consistently formatted code makes life a great deal
|
||||
easier for everyone involved.
|
||||
* Commit log messages: When committing changes, do so often and
|
||||
clearly -- Even if you have changed only 1 character in a code
|
||||
comment. This means that commit log messages should clearly state
|
||||
exactly what the change does and why. If it fixes a known issue,
|
||||
then mention the issue number in the commit log. E.g.:
|
||||
|
||||
> Fixes return value for `foo/boo.Baz()` to be consistent with
|
||||
> the rest of the API. This addresses issue #32
|
||||
|
||||
Do not pile a lot of unrelated changes into a single commit.
|
||||
Pick and chose only those changes for a single commit, which are
|
||||
directly related. We would much rather see a hundred commits
|
||||
saying nothing but `"Runs go fmt"` in between any real fixes
|
||||
than have these style changes embedded in those real fixes.
|
||||
It creates a lot of noise when trying to review code.
|
||||
|
||||
|
10
CONTRIBUTORS
10
CONTRIBUTORS
|
@ -1,10 +0,0 @@
|
|||
# This is the list of people who can contribute (or have contributed) to this
|
||||
# project. This includes code, documentation, testing, content creation and
|
||||
# bugfixes.
|
||||
#
|
||||
# Names should be added to this file like so:
|
||||
# Name [<email address>]
|
||||
#
|
||||
# Please keep the list sorted.
|
||||
|
||||
Jim Teeuwen <jimteeuwen at gmail dot com>
|
153
README.md
153
README.md
|
@ -1,47 +1,66 @@
|
|||
## bindata
|
||||
|
||||
This tool converts any file into managable Go source code. Useful for embedding
|
||||
binary data into a go program. The file data is optionally gzip compressed
|
||||
before being converted to a raw byte slice.
|
||||
This package converts any file into managable Go source code. Useful for
|
||||
embedding binary data into a go program. The file data is optionally gzip
|
||||
compressed before being converted to a raw byte slice.
|
||||
|
||||
It comes with a command line tool in the `go-bindata` sub directory.
|
||||
This tool offers a set of command line options, used to customize the
|
||||
output being generated.
|
||||
|
||||
|
||||
### Usage
|
||||
|
||||
The simplest invocation is to pass it only the input file name.
|
||||
The output file and code settings are inferred from this automatically.
|
||||
Conversion is done on one or more sets of files. They are all embedded in a new
|
||||
Go source file, along with a table of contents and an `Asset` function,
|
||||
which allows quick access to the asset, based on its name.
|
||||
|
||||
$ go-bindata testdata/gophercolor.png
|
||||
[w] No output file specified. Using 'testdata/gophercolor.png.go'.
|
||||
[w] No package name specified. Using 'main'.
|
||||
[w] No function name specified. Using 'testdata_gophercolor_png'.
|
||||
The simplest invocation generates a `bindata.go` file in the current
|
||||
working directory. It includes all assets from the `data` directory.
|
||||
|
||||
This creates the `testdata/gophercolor.png.go` file which has a package
|
||||
declaration with name `main` and one function named `testdata_gophercolor_png` with
|
||||
the following signature:
|
||||
$ go-bindata data/
|
||||
|
||||
```go
|
||||
func testdata_gophercolor_png() []byte
|
||||
```
|
||||
To include all input sub-directories recursively, use the elipsis postfix
|
||||
as defined for Go import paths. Otherwise it will only consider assets in the
|
||||
input directory itself.
|
||||
|
||||
You can now simply include the new .go file in your program and call
|
||||
`testdata_gophercolor_png()` to get the (uncompressed) image data. The function panics
|
||||
if something went wrong during decompression. See the testdata directory for
|
||||
example input and output files for various modes.
|
||||
$ go-bindata data/...
|
||||
|
||||
Aternatively, you can pipe the input file data into stdin. `go-bindata` will
|
||||
then spit out the generated Go code to stdout. This does require explicitly
|
||||
naming the desired function name, as it can not be inferred from the
|
||||
input data. The package name will still default to 'main'.
|
||||
To specify the name of the output file being generated, we use the following:
|
||||
|
||||
$ cat testdata/gophercolor.png | go-bindata -f gophercolor_png | gofmt
|
||||
$ go-bindata -o myfile.go data/
|
||||
|
||||
Invoke the program with the `-h` flag for more options.
|
||||
Multiple input directories can be specified if necessary.
|
||||
|
||||
In order to strip off a part of the generated function name, we can use the `-prefix` flag.
|
||||
In the above example, the input file `testdata/gophercolor.png` yields a function named
|
||||
`testdata_gophercolor_png`. If we want the `testdata` component to be left out, we invoke
|
||||
the program as follows:
|
||||
$ go-bindata dir1/... /path/to/dir3/... dir3
|
||||
|
||||
$ go-bindata -prefix "testdata/" testdata/gophercolor.png
|
||||
|
||||
The following paragraphs detail some of the command line options which can
|
||||
supplied to `go-bindata`. Refer to the `testdata/out` directory for various
|
||||
output examples from the assets in `testdata/in`. Each example uses different
|
||||
command line options.
|
||||
|
||||
|
||||
### Debug vs Release builds
|
||||
|
||||
When invoking the program with the `-debug` flag, the generated code does
|
||||
not actually include the asset data. Instead, it generates function stubs
|
||||
which load the data from the original file on disk. The asset API remains
|
||||
identical between debug and release builds, so your code will not have to
|
||||
change.
|
||||
|
||||
This is useful during development when you expect the assets to change often.
|
||||
The host application using these assets uses the same API in both cases and
|
||||
will not have to care where the actual data comes from.
|
||||
|
||||
An example is a Go webserver with some embedded, static web content like
|
||||
HTML, JS and CSS files. While developing it, you do not want to rebuild the
|
||||
whole server and restart it every time you make a change to a bit of
|
||||
javascript. You just want to build and launch the server once. Then just press
|
||||
refresh in the browser to see those changes. Embedding the assets with the
|
||||
`debug` flag allows you to do just that. When you are finished developing and
|
||||
ready for deployment, just re-invoke `go-bindata` without the `-debug` flag.
|
||||
It will now embed the latest version of the assets.
|
||||
|
||||
|
||||
### Lower memory footprint
|
||||
|
@ -97,9 +116,9 @@ func myfile() []byte {
|
|||
|
||||
### Optional compression
|
||||
|
||||
When the `-uncompressed` flag is given, the supplied resource is *not* GZIP compressed
|
||||
before being turned into Go code. The data should still be accessed through
|
||||
a function call, so nothing changes in the usage of the generated file.
|
||||
When the `-nocompress` flag is given, the supplied resource is *not* GZIP
|
||||
compressed before being turned into Go code. The data should still be accessed
|
||||
through a function call, so nothing changes in the usage of the generated file.
|
||||
|
||||
This feature is useful if you do not care for compression, or the supplied
|
||||
resource is already compressed. Doing it again would not add any value and may
|
||||
|
@ -108,66 +127,36 @@ even increase the size of the data.
|
|||
The default behaviour of the program is to use compression.
|
||||
|
||||
|
||||
### Table of Contents
|
||||
### Path prefix stripping
|
||||
|
||||
With the `-toc` flag, we can have `go-bindata` create a table of contents for all the files
|
||||
which have been generated by the tool. It does this by first generating a new file named
|
||||
`bindata-toc.go`. This contains a global map of type `map[string] func() []byte`. It uses the
|
||||
input filename as the key and the data function as the value. We can use this
|
||||
to fetch all data for our files, matching a given pattern.
|
||||
|
||||
It then appands an `init` function to each generated file, which simply makes the data
|
||||
function append itself to the global `bindata` map.
|
||||
|
||||
Once you have compiled your program with all these new files and run it, the map will
|
||||
be populated by all generated data files.
|
||||
|
||||
**Note**: The `bindata-toc.go` file will not be created when we run in `pipe` mode.
|
||||
The reason being, that the tool does not write any files at all, as it has no idea
|
||||
where to save them. The data file is written to `stdout` instead after all.
|
||||
|
||||
|
||||
#### Table of Contents keys
|
||||
|
||||
The keys used in the `go_bindata` map, are the same as the input file name passed to `go-bindata`.
|
||||
This includes the fully qualified (absolute) path. In most cases, this is not desireable, as it
|
||||
puts potentially sensitive information in your code base. For this purpose, the tool supplies
|
||||
another command line flag `-prefix`. This accepts a portion of a path name, which should be
|
||||
stripped off from the map keys and function names.
|
||||
The keys used in the `_bindata` map, are the same as the input file name
|
||||
passed to `go-bindata`. This includes the path. In most cases, this is not
|
||||
desireable, as it puts potentially sensitive information in your code base.
|
||||
For this purpose, the tool supplies another command line flag `-prefix`.
|
||||
This accepts a portion of a path name, which should be stripped off from
|
||||
the map keys and function names.
|
||||
|
||||
For example, running without the `-prefix` flag, we get:
|
||||
|
||||
$ go-bindata /path/to/templates/foo.html
|
||||
|
||||
go_bindata["/path/to/templates/foo.html"] = path_to_templates_foo_html
|
||||
$ go-bindata /path/to/templates/
|
||||
|
||||
_bindata["/path/to/templates/foo.html"] = path_to_templates_foo_html
|
||||
|
||||
Running with the `-prefix` flag, we get:
|
||||
|
||||
$ go-bindata -prefix "/path/to/" /path/to/templates/foo.html
|
||||
|
||||
go_bindata["templates/foo.html"] = templates_foo_html
|
||||
$ go-bindata -prefix "/path/to/" /path/to/templates/
|
||||
|
||||
_bindata["templates/foo.html"] = templates_foo_html
|
||||
|
||||
|
||||
#### bindata-toc.go
|
||||
### Build tags
|
||||
|
||||
The `bindata-toc.go` file is very simple and looks as follows:
|
||||
|
||||
```go
|
||||
package $PACKAGENAME
|
||||
|
||||
// Global Table of Contents map. Generated by go-bindata.
|
||||
// After startup of the program, all generated data files will
|
||||
// put themselves in this map. The key is the full filename, as
|
||||
// supplied to go-bindata.
|
||||
var go_bindata = make(map[string] func() []byte)
|
||||
```
|
||||
|
||||
#### Build tags
|
||||
|
||||
With the optional -tags flag, you can specify any go build tags that
|
||||
With the optional `-tags` flag, you can specify any go build tags that
|
||||
must be fulfilled for the output file to be included in a build. This
|
||||
is useful for including binary data in multiple formats, where the desired
|
||||
format is specified at build time with the appropriate tag(s).
|
||||
is useful when including binary data in multiple formats, where the desired
|
||||
format is specified at build time with the appropriate tags.
|
||||
|
||||
The tags are appended to a `// +build` line in the beginning of the output file
|
||||
and must follow the build tags syntax specified by the go tool.
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
// This work is subject to the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
|
||||
// license. Its contents can be found at:
|
||||
// http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
package bindata
|
||||
|
||||
// Asset holds information about a single asset to be processed.
|
||||
type Asset struct {
|
||||
Path string // Full file path.
|
||||
Name string // Key used in TOC -- name by which asset is referenced.
|
||||
Func string // Function name for the procedure returning the asset contents.
|
||||
}
|
|
@ -0,0 +1,185 @@
|
|||
// This work is subject to the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
|
||||
// license. Its contents can be found at:
|
||||
// http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
package bindata
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// InputConfig defines options on a asset directory to be convert.
|
||||
type InputConfig struct {
|
||||
// Path defines a directory containing asset files to be included
|
||||
// in the generated output.
|
||||
Path string
|
||||
|
||||
// Recusive defines whether subdirectories of Path
|
||||
// should be recursively included in the conversion.
|
||||
Recursive bool
|
||||
}
|
||||
|
||||
// Config defines a set of options for the asset conversion.
|
||||
type Config struct {
|
||||
// Name of the package to use. Defaults to 'main'.
|
||||
Package string
|
||||
|
||||
// Tags specify a set of optional build tags, which should be
|
||||
// included in the generated output. The tags are appended to a
|
||||
// `// +build` line in the beginning of the output file
|
||||
// and must follow the build tags syntax specified by the go tool.
|
||||
Tags string
|
||||
|
||||
// Input defines the directory path, containing all asset files as
|
||||
// well as whether to recursively process assets in any sub directories.
|
||||
Input []InputConfig
|
||||
|
||||
// Output defines the output file for the generated code.
|
||||
// If left empty, this defaults to 'bindata.go' in the current
|
||||
// working directory.
|
||||
Output string
|
||||
|
||||
// Prefix defines a path prefix which should be stripped from all
|
||||
// file names when generating the keys in the table of contents.
|
||||
// For example, running without the `-prefix` flag, we get:
|
||||
//
|
||||
// $ go-bindata /path/to/templates
|
||||
// go_bindata["/path/to/templates/foo.html"] = _path_to_templates_foo_html
|
||||
//
|
||||
// Running with the `-prefix` flag, we get:
|
||||
//
|
||||
// $ go-bindata -prefix "/path/to/" /path/to/templates/foo.html
|
||||
// go_bindata["templates/foo.html"] = templates_foo_html
|
||||
Prefix string
|
||||
|
||||
// NoMemCopy will alter the way the output file is generated.
|
||||
//
|
||||
// It will employ a hack that allows us to read the file data directly from
|
||||
// the compiled program's `.rodata` section. This ensures that when we call
|
||||
// call our generated function, we omit unnecessary mem copies.
|
||||
//
|
||||
// The downside of this, is that it requires dependencies on the `reflect` and
|
||||
// `unsafe` packages. These may be restricted on platforms like AppEngine and
|
||||
// thus prevent you from using this mode.
|
||||
//
|
||||
// Another disadvantage is that the byte slice we create, is strictly read-only.
|
||||
// For most use-cases this is not a problem, but if you ever try to alter the
|
||||
// returned byte slice, a runtime panic is thrown. Use this mode only on target
|
||||
// platforms where memory constraints are an issue.
|
||||
//
|
||||
// The default behaviour is to use the old code generation method. This
|
||||
// prevents the two previously mentioned issues, but will employ at least one
|
||||
// extra memcopy and thus increase memory requirements.
|
||||
//
|
||||
// For instance, consider the following two examples:
|
||||
//
|
||||
// This would be the default mode, using an extra memcopy but gives a safe
|
||||
// implementation without dependencies on `reflect` and `unsafe`:
|
||||
//
|
||||
// func myfile() []byte {
|
||||
// return []byte{0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a}
|
||||
// }
|
||||
//
|
||||
// Here is the same functionality, but uses the `.rodata` hack.
|
||||
// The byte slice returned from this example can not be written to without
|
||||
// generating a runtime error.
|
||||
//
|
||||
// var _myfile = "\x89\x50\x4e\x47\x0d\x0a\x1a"
|
||||
//
|
||||
// func myfile() []byte {
|
||||
// var empty [0]byte
|
||||
// sx := (*reflect.StringHeader)(unsafe.Pointer(&_myfile))
|
||||
// b := empty[:]
|
||||
// bx := (*reflect.SliceHeader)(unsafe.Pointer(&b))
|
||||
// bx.Data = sx.Data
|
||||
// bx.Len = len(_myfile)
|
||||
// bx.Cap = bx.Len
|
||||
// return b
|
||||
// }
|
||||
NoMemCopy bool
|
||||
|
||||
// NoCompress means the assets are /not/ GZIP compressed before being turned
|
||||
// into Go code. The generated function will automatically unzip
|
||||
// the file data when called. Defaults to false.
|
||||
NoCompress bool
|
||||
|
||||
// Perform a debug build. This generates an asset file, which
|
||||
// loads the asset contents directly from disk at their original
|
||||
// location, instead of embedding the contents in the code.
|
||||
//
|
||||
// This is mostly useful if you anticipate that the assets are
|
||||
// going to change during your development cycle. You will always
|
||||
// want your code to access the latest version of the asset.
|
||||
// Only in release mode, will the assets actually be embedded
|
||||
// in the code. The default behaviour is Release mode.
|
||||
Debug bool
|
||||
|
||||
// Recursively process all assets in the input directory and its
|
||||
// sub directories. This defaults to false, so only files in the
|
||||
// input directory itself are read.
|
||||
Recursive bool
|
||||
}
|
||||
|
||||
// NewConfig returns a default configuration struct.
|
||||
func NewConfig() *Config {
|
||||
c := new(Config)
|
||||
c.Package = "main"
|
||||
c.NoMemCopy = false
|
||||
c.NoCompress = false
|
||||
c.Debug = false
|
||||
c.Recursive = false
|
||||
c.Output = "./bindata.go"
|
||||
return c
|
||||
}
|
||||
|
||||
// validate ensures the config has sane values.
|
||||
// Part of which means checking if certain file/directory paths exist.
|
||||
func (c *Config) validate() error {
|
||||
if len(c.Package) == 0 {
|
||||
return fmt.Errorf("Missing package name")
|
||||
}
|
||||
|
||||
for _, input := range c.Input {
|
||||
stat, err := os.Lstat(input.Path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Failed to stat input path '%s': %v", input.Path, err)
|
||||
}
|
||||
|
||||
if !stat.IsDir() {
|
||||
return fmt.Errorf("Input path '%s' is not a directory.", input.Path)
|
||||
}
|
||||
}
|
||||
|
||||
if len(c.Output) == 0 {
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Unable to determine current working directory.")
|
||||
}
|
||||
|
||||
c.Output = filepath.Join(cwd, "bindata.go")
|
||||
}
|
||||
|
||||
stat, err := os.Lstat(c.Output)
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
return fmt.Errorf("Output path: %v", err)
|
||||
}
|
||||
|
||||
// File does not exist. This is fine, just make
|
||||
// sure the directory it is to be in exists.
|
||||
dir, _ := filepath.Split(c.Output)
|
||||
err = os.MkdirAll(dir, 0744)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("Create output directory: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
if stat != nil && stat.IsDir() {
|
||||
return fmt.Errorf("Output path is a directory.")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,152 @@
|
|||
// This work is subject to the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
|
||||
// license. Its contents can be found at:
|
||||
// http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
package bindata
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
// Translate reads assets from an input directory, converts them
|
||||
// to Go code and writes new files to the output specified
|
||||
// in the given configuration.
|
||||
func Translate(c *Config) error {
|
||||
var toc []Asset
|
||||
|
||||
// Ensure our configuration has sane values.
|
||||
err := c.validate()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Locate all the assets.
|
||||
for _, input := range c.Input {
|
||||
err = findFiles(input.Path, c.Prefix, input.Recursive, &toc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Create output file.
|
||||
fd, err := os.Create(c.Output)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer fd.Close()
|
||||
|
||||
// Write build tags, if applicable.
|
||||
if len(c.Tags) > 0 {
|
||||
_, err = fmt.Fprintf(fd, "// +build %s\n\n", c.Tags)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// Write package declaration.
|
||||
_, err = fmt.Fprintf(fd, "package %s\n\n", c.Package)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Write assets.
|
||||
if c.Debug {
|
||||
err = writeDebug(fd, toc)
|
||||
} else {
|
||||
err = writeRelease(fd, c, toc)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Write table of contents
|
||||
return writeTOC(fd, toc)
|
||||
}
|
||||
|
||||
// findFiles recursively finds all the file paths in the given directory tree.
|
||||
// They are added to the given map as keys. Values will be safe function names
|
||||
// for each file, which will be used when generating the output code.
|
||||
func findFiles(dir, prefix string, recursive bool, toc *[]Asset) error {
|
||||
if len(prefix) > 0 {
|
||||
dir, _ = filepath.Abs(dir)
|
||||
prefix, _ = filepath.Abs(prefix)
|
||||
}
|
||||
|
||||
fd, err := os.Open(dir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer fd.Close()
|
||||
|
||||
list, err := fd.Readdir(0)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, file := range list {
|
||||
var asset Asset
|
||||
asset.Path = filepath.Join(dir, file.Name())
|
||||
asset.Name = asset.Path
|
||||
|
||||
if file.IsDir() {
|
||||
if recursive {
|
||||
findFiles(asset.Path, prefix, recursive, toc)
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if strings.HasPrefix(asset.Name, prefix) {
|
||||
asset.Name = asset.Name[len(prefix):]
|
||||
}
|
||||
|
||||
// If we have a leading slash, get rid of it.
|
||||
if len(asset.Name) > 0 && asset.Name[0] == '/' {
|
||||
asset.Name = asset.Name[1:]
|
||||
}
|
||||
|
||||
// This shouldn't happen.
|
||||
if len(asset.Name) == 0 {
|
||||
return fmt.Errorf("Invalid file: %v", asset.Path)
|
||||
}
|
||||
|
||||
asset.Func = safeFunctionName(asset.Name)
|
||||
asset.Path, _ = filepath.Abs(asset.Path)
|
||||
*toc = append(*toc, asset)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var regFuncName = regexp.MustCompile(`[^a-zA-Z0-9_]`)
|
||||
|
||||
// safeFunctionName converts the given name into a name
|
||||
// which qualifies as a valid function identifier.
|
||||
func safeFunctionName(name string) string {
|
||||
name = strings.ToLower(name)
|
||||
name = regFuncName.ReplaceAllString(name, "_")
|
||||
|
||||
// Get rid of "__" instances for niceness.
|
||||
for strings.Index(name, "__") > -1 {
|
||||
name = strings.Replace(name, "__", "_", -1)
|
||||
}
|
||||
|
||||
// Leading underscores are silly (unless they prefix a digit (see below)).
|
||||
for len(name) > 1 && name[0] == '_' {
|
||||
name = name[1:]
|
||||
}
|
||||
|
||||
// Identifier can't start with a digit.
|
||||
if unicode.IsDigit(rune(name[0])) {
|
||||
name = "_" + name
|
||||
}
|
||||
|
||||
return name
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
// This work is subject to the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
|
||||
// license. Its contents can be found at:
|
||||
// http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
package bindata
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
// writeDebug writes the debug code file.
|
||||
func writeDebug(w io.Writer, toc []Asset) error {
|
||||
err := writeDebugHeader(w)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for i := range toc {
|
||||
err = writeDebugAsset(w, &toc[i])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// writeDebugHeader writes output file headers.
|
||||
// This targets debug builds.
|
||||
func writeDebugHeader(w io.Writer) error {
|
||||
_, err := fmt.Fprintf(w, `import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
)
|
||||
|
||||
// bindata_read reads the given file from disk. It returns
|
||||
// an error on failure.
|
||||
func bindata_read(path, name string) ([]byte, error) {
|
||||
buf, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Error reading asset %%s at %%s: %%v", name, path, err)
|
||||
}
|
||||
return buf, err
|
||||
}
|
||||
|
||||
`)
|
||||
return err
|
||||
}
|
||||
|
||||
// writeDebugAsset write a debug entry for the given asset.
|
||||
// A debug entry is simply a function which reads the asset from
|
||||
// the original file (e.g.: from disk).
|
||||
func writeDebugAsset(w io.Writer, asset *Asset) error {
|
||||
_, err := fmt.Fprintf(w, `
|
||||
// %s reads file data from disk.
|
||||
// It panics if something went wrong in the process.
|
||||
func %s() ([]byte, error) {
|
||||
return bindata_read(
|
||||
%q,
|
||||
%q,
|
||||
)
|
||||
}
|
||||
`, asset.Func, asset.Func, asset.Path, asset.Name)
|
||||
return err
|
||||
}
|
|
@ -0,0 +1,129 @@
|
|||
// This work is subject to the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
|
||||
// license. Its contents can be found at:
|
||||
// http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
/*
|
||||
bindata converts any file into managable Go source code. Useful for
|
||||
embedding binary data into a go program. The file data is optionally gzip
|
||||
compressed before being converted to a raw byte slice.
|
||||
|
||||
The following paragraphs cover some of the customization options
|
||||
which can be specified in the Config struct, which must be passed into
|
||||
the Translate() call.
|
||||
|
||||
|
||||
Debug vs Release builds
|
||||
|
||||
When used with the `Debug` option, the generated code does not actually include
|
||||
the asset data. Instead, it generates function stubs which load the data from
|
||||
the original file on disk. The asset API remains identical between debug and
|
||||
release builds, so your code will not have to change.
|
||||
|
||||
This is useful during development when you expect the assets to change often.
|
||||
The host application using these assets uses the same API in both cases and
|
||||
will not have to care where the actual data comes from.
|
||||
|
||||
An example is a Go webserver with some embedded, static web content like
|
||||
HTML, JS and CSS files. While developing it, you do not want to rebuild the
|
||||
whole server and restart it every time you make a change to a bit of
|
||||
javascript. You just want to build and launch the server once. Then just press
|
||||
refresh in the browser to see those changes. Embedding the assets with the
|
||||
`debug` flag allows you to do just that. When you are finished developing and
|
||||
ready for deployment, just re-invoke `go-bindata` without the `-debug` flag.
|
||||
It will now embed the latest version of the assets.
|
||||
|
||||
|
||||
Lower memory footprint
|
||||
|
||||
The `NoMemCopy` option will alter the way the output file is generated.
|
||||
It will employ a hack that allows us to read the file data directly from
|
||||
the compiled program's `.rodata` section. This ensures that when we call
|
||||
call our generated function, we omit unnecessary memcopies.
|
||||
|
||||
The downside of this, is that it requires dependencies on the `reflect` and
|
||||
`unsafe` packages. These may be restricted on platforms like AppEngine and
|
||||
thus prevent you from using this mode.
|
||||
|
||||
Another disadvantage is that the byte slice we create, is strictly read-only.
|
||||
For most use-cases this is not a problem, but if you ever try to alter the
|
||||
returned byte slice, a runtime panic is thrown. Use this mode only on target
|
||||
platforms where memory constraints are an issue.
|
||||
|
||||
The default behaviour is to use the old code generation method. This
|
||||
prevents the two previously mentioned issues, but will employ at least one
|
||||
extra memcopy and thus increase memory requirements.
|
||||
|
||||
For instance, consider the following two examples:
|
||||
|
||||
This would be the default mode, using an extra memcopy but gives a safe
|
||||
implementation without dependencies on `reflect` and `unsafe`:
|
||||
|
||||
func myfile() []byte {
|
||||
return []byte{0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a}
|
||||
}
|
||||
|
||||
Here is the same functionality, but uses the `.rodata` hack.
|
||||
The byte slice returned from this example can not be written to without
|
||||
generating a runtime error.
|
||||
|
||||
var _myfile = "\x89\x50\x4e\x47\x0d\x0a\x1a"
|
||||
|
||||
func myfile() []byte {
|
||||
var empty [0]byte
|
||||
sx := (*reflect.StringHeader)(unsafe.Pointer(&_myfile))
|
||||
b := empty[:]
|
||||
bx := (*reflect.SliceHeader)(unsafe.Pointer(&b))
|
||||
bx.Data = sx.Data
|
||||
bx.Len = len(_myfile)
|
||||
bx.Cap = bx.Len
|
||||
return b
|
||||
}
|
||||
|
||||
|
||||
Optional compression
|
||||
|
||||
The NoCompress option indicates that the supplied assets are *not* GZIP
|
||||
compressed before being turned into Go code. The data should still be accessed
|
||||
through a function call, so nothing changes in the API.
|
||||
|
||||
This feature is useful if you do not care for compression, or the supplied
|
||||
resource is already compressed. Doing it again would not add any value and may
|
||||
even increase the size of the data.
|
||||
|
||||
The default behaviour of the program is to use compression.
|
||||
|
||||
|
||||
Path prefix stripping
|
||||
|
||||
The keys used in the `_bindata` map are the same as the input file name
|
||||
passed to `go-bindata`. This includes the path. In most cases, this is not
|
||||
desireable, as it puts potentially sensitive information in your code base.
|
||||
For this purpose, the tool supplies another command line flag `-prefix`.
|
||||
This accepts a portion of a path name, which should be stripped off from
|
||||
the map keys and function names.
|
||||
|
||||
For example, running without the `-prefix` flag, we get:
|
||||
|
||||
$ go-bindata /path/to/templates/
|
||||
|
||||
_bindata["/path/to/templates/foo.html"] = path_to_templates_foo_html
|
||||
|
||||
Running with the `-prefix` flag, we get:
|
||||
|
||||
$ go-bindata -prefix "/path/to/" /path/to/templates/
|
||||
|
||||
_bindata["templates/foo.html"] = templates_foo_html
|
||||
|
||||
|
||||
Build tags
|
||||
|
||||
With the optional Tags field, you can specify any go build tags that
|
||||
must be fulfilled for the output file to be included in a build. This
|
||||
is useful when including binary data in multiple formats, where the desired
|
||||
format is specified at build time with the appropriate tags.
|
||||
|
||||
The tags are appended to a `// +build` line in the beginning of the output file
|
||||
and must follow the build tags syntax specified by the go tool.
|
||||
|
||||
*/
|
||||
package bindata
|
|
@ -0,0 +1,91 @@
|
|||
// This work is subject to the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
|
||||
// license. Its contents can be found at:
|
||||
// http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/jteeuwen/go-bindata"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cfg := parseArgs()
|
||||
err := bindata.Translate(cfg)
|
||||
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "bindata: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
// parseArgs create s a new, filled configuration instance
|
||||
// by reading and parsing command line options.
|
||||
//
|
||||
// This function exits the program with an error, if
|
||||
// any of the command line options are incorrect.
|
||||
func parseArgs() *bindata.Config {
|
||||
var version bool
|
||||
|
||||
c := bindata.NewConfig()
|
||||
|
||||
flag.Usage = func() {
|
||||
fmt.Printf("Usage: %s [options] <input directories>\n\n", os.Args[0])
|
||||
flag.PrintDefaults()
|
||||
}
|
||||
|
||||
flag.BoolVar(&c.Debug, "debug", c.Debug, "Do not embed the assets, but provide the embedding API. Contents will still be loaded from disk.")
|
||||
flag.StringVar(&c.Tags, "tags", c.Tags, "Optional set of uild tags to include.")
|
||||
flag.StringVar(&c.Prefix, "prefix", c.Prefix, "Optional path prefix to strip off asset names.")
|
||||
flag.StringVar(&c.Package, "pkg", c.Package, "Package name to use in the generated code.")
|
||||
flag.BoolVar(&c.NoMemCopy, "nomemcopy", c.NoMemCopy, "Use a .rodata hack to get rid of unnecessary memcopies. Refer to the documentation to see what implications this carries.")
|
||||
flag.BoolVar(&c.NoCompress, "nocompress", c.NoCompress, "Assets will *not* be GZIP compressed when this flag is specified.")
|
||||
flag.StringVar(&c.Output, "o", c.Output, "Optional name of the output file to be generated.")
|
||||
flag.BoolVar(&version, "version", false, "Displays version information.")
|
||||
flag.Parse()
|
||||
|
||||
if version {
|
||||
fmt.Printf("%s\n", Version())
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
// Make sure we have input paths.
|
||||
if flag.NArg() == 0 {
|
||||
fmt.Fprintf(os.Stderr, "Missing <input dir>\n\n")
|
||||
flag.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// Create input configurations.
|
||||
c.Input = make([]bindata.InputConfig, flag.NArg())
|
||||
for i := range c.Input {
|
||||
c.Input[i] = parseInput(flag.Arg(i))
|
||||
}
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
// parseRecursive determines whether the given path has a recrusive indicator and
|
||||
// returns a new path with the recursive indicator chopped off if it does.
|
||||
//
|
||||
// ex:
|
||||
// /path/to/foo/... -> (/path/to/foo, true)
|
||||
// /path/to/bar -> (/path/to/bar, false)
|
||||
func parseInput(path string) bindata.InputConfig {
|
||||
if strings.HasSuffix(path, "/...") {
|
||||
return bindata.InputConfig{
|
||||
Path: filepath.Clean(path[:len(path)-4]),
|
||||
Recursive: true,
|
||||
}
|
||||
} else {
|
||||
return bindata.InputConfig{
|
||||
Path: filepath.Clean(path),
|
||||
Recursive: false,
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
// license. Its contents can be found at:
|
||||
// http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
package bindata
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
@ -10,8 +10,8 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
AppName = "bindata"
|
||||
AppVersionMajor = 2
|
||||
AppName = "go-bindata"
|
||||
AppVersionMajor = 3
|
||||
AppVersionMinor = 1
|
||||
)
|
||||
|
39
lib/toc.go
39
lib/toc.go
|
@ -1,39 +0,0 @@
|
|||
// This work is subject to the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
|
||||
// license. Its contents can be found at:
|
||||
// http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
package bindata
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// createTOC writes a table of contents file to the given location.
|
||||
func CreateTOC(dir, pkgname string) error {
|
||||
file := filepath.Join(dir, "bindata-toc.go")
|
||||
code := fmt.Sprintf(`package %s
|
||||
|
||||
// Global Table of Contents map. Generated by go-bindata.
|
||||
// After startup of the program, all generated data files will
|
||||
// put themselves in this map. The key is the full filename, as
|
||||
// supplied to go-bindata.
|
||||
var go_bindata = make(map[string]func() []byte)
|
||||
`, pkgname)
|
||||
|
||||
return ioutil.WriteFile(file, []byte(code), 0600)
|
||||
}
|
||||
|
||||
// WriteTOCInit writes the TOC init function for a given data file
|
||||
// replacing the prefix in the filename by "", funcname being the translated function name
|
||||
func WriteTOCInit(output io.Writer, filename, prefix, funcname string) {
|
||||
filename = strings.Replace(filename, prefix, "", 1)
|
||||
fmt.Fprintf(output, `
|
||||
func init() {
|
||||
go_bindata[%q] = %s
|
||||
}
|
||||
`, filename, funcname)
|
||||
}
|
189
lib/translate.go
189
lib/translate.go
|
@ -1,189 +0,0 @@
|
|||
// This work is subject to the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
|
||||
// license. Its contents can be found at:
|
||||
// http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
package bindata
|
||||
|
||||
import (
|
||||
"compress/gzip"
|
||||
"fmt"
|
||||
"io"
|
||||
"regexp"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
var regFuncName = regexp.MustCompile(`[^a-zA-Z0-9_]`)
|
||||
|
||||
// translate translates the input file to go source code.
|
||||
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)
|
||||
} else {
|
||||
translate_nomemcpy_comp(input, output, pkgname, funcname)
|
||||
}
|
||||
} else {
|
||||
if uncompressed {
|
||||
translate_memcpy_uncomp(input, output, pkgname, funcname)
|
||||
} else {
|
||||
translate_memcpy_comp(input, output, pkgname, funcname)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// input -> gzip -> gowriter -> output.
|
||||
func translate_memcpy_comp(input io.Reader, output io.Writer, pkgname, funcname string) {
|
||||
fmt.Fprintf(output, `package %s
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"io"
|
||||
)
|
||||
|
||||
// %s returns raw, uncompressed file data.
|
||||
func %s() []byte {
|
||||
gz, err := gzip.NewReader(bytes.NewBuffer([]byte{`, pkgname, funcname, funcname)
|
||||
|
||||
gz := gzip.NewWriter(&ByteWriter{Writer: output})
|
||||
io.Copy(gz, input)
|
||||
gz.Close()
|
||||
|
||||
fmt.Fprint(output, `
|
||||
}))
|
||||
|
||||
if err != nil {
|
||||
panic("Decompression failed: " + err.Error())
|
||||
}
|
||||
|
||||
var b bytes.Buffer
|
||||
io.Copy(&b, gz)
|
||||
gz.Close()
|
||||
|
||||
return b.Bytes()
|
||||
}
|
||||
`)
|
||||
}
|
||||
|
||||
// input -> gzip -> gowriter -> output.
|
||||
func translate_memcpy_uncomp(input io.Reader, output io.Writer, pkgname, funcname string) {
|
||||
fmt.Fprintf(output, `package %s
|
||||
|
||||
// %s returns raw file data.
|
||||
func %s() []byte {
|
||||
return []byte{`, pkgname, funcname, funcname)
|
||||
|
||||
io.Copy(&ByteWriter{Writer: output}, input)
|
||||
|
||||
fmt.Fprint(output, `
|
||||
}
|
||||
}
|
||||
`)
|
||||
}
|
||||
|
||||
// input -> gzip -> gowriter -> output.
|
||||
func translate_nomemcpy_comp(input io.Reader, output io.Writer, pkgname, funcname string) {
|
||||
fmt.Fprintf(output, `package %s
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"io"
|
||||
"reflect"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var _%s = "`, pkgname, funcname)
|
||||
|
||||
gz := gzip.NewWriter(&StringWriter{Writer: output})
|
||||
io.Copy(gz, input)
|
||||
gz.Close()
|
||||
|
||||
fmt.Fprintf(output, `"
|
||||
|
||||
// %s returns raw, uncompressed file data.
|
||||
func %s() []byte {
|
||||
var empty [0]byte
|
||||
sx := (*reflect.StringHeader)(unsafe.Pointer(&_%s))
|
||||
b := empty[:]
|
||||
bx := (*reflect.SliceHeader)(unsafe.Pointer(&b))
|
||||
bx.Data = sx.Data
|
||||
bx.Len = len(_%s)
|
||||
bx.Cap = bx.Len
|
||||
|
||||
gz, err := gzip.NewReader(bytes.NewBuffer(b))
|
||||
|
||||
if err != nil {
|
||||
panic("Decompression failed: " + err.Error())
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
io.Copy(&buf, gz)
|
||||
gz.Close()
|
||||
|
||||
return buf.Bytes()
|
||||
}
|
||||
`, funcname, funcname, funcname, funcname)
|
||||
}
|
||||
|
||||
// input -> gowriter -> output.
|
||||
func translate_nomemcpy_uncomp(input io.Reader, output io.Writer, pkgname, funcname string) {
|
||||
fmt.Fprintf(output, `package %s
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
var _%s = "`, pkgname, funcname)
|
||||
|
||||
io.Copy(&StringWriter{Writer: output}, input)
|
||||
|
||||
fmt.Fprintf(output, `"
|
||||
|
||||
// %s returns raw file data.
|
||||
//
|
||||
// WARNING: The returned byte slice is READ-ONLY.
|
||||
// Attempting to alter the slice contents will yield a runtime panic.
|
||||
func %s() []byte {
|
||||
var empty [0]byte
|
||||
sx := (*reflect.StringHeader)(unsafe.Pointer(&_%s))
|
||||
b := empty[:]
|
||||
bx := (*reflect.SliceHeader)(unsafe.Pointer(&b))
|
||||
bx.Data = sx.Data
|
||||
bx.Len = len(_%s)
|
||||
bx.Cap = bx.Len
|
||||
return b
|
||||
}
|
||||
`, funcname, funcname, funcname, funcname)
|
||||
}
|
||||
|
||||
// safeFuncname creates a safe function name from the input path.
|
||||
func SafeFuncname(in, prefix string) string {
|
||||
name := strings.Replace(in, prefix, "", 1)
|
||||
|
||||
if len(name) == 0 {
|
||||
name = in
|
||||
}
|
||||
|
||||
name = strings.ToLower(name)
|
||||
name = regFuncName.ReplaceAllString(name, "_")
|
||||
|
||||
if unicode.IsDigit(rune(name[0])) {
|
||||
// Identifier can't start with a digit.
|
||||
name = "_" + name
|
||||
}
|
||||
|
||||
// Get rid of "__" instances for niceness.
|
||||
for strings.Index(name, "__") > -1 {
|
||||
name = strings.Replace(name, "__", "_", -1)
|
||||
}
|
||||
|
||||
// Leading underscore is silly.
|
||||
if name[0] == '_' {
|
||||
name = name[1:]
|
||||
}
|
||||
|
||||
return name
|
||||
}
|
162
main.go
162
main.go
|
@ -1,162 +0,0 @@
|
|||
// This work is subject to the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
|
||||
// license. Its contents can be found at:
|
||||
// http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/jteeuwen/go-bindata/lib"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
var (
|
||||
pipe = false
|
||||
in = ""
|
||||
out = flag.String("out", "", "Optional path and name of the output file.")
|
||||
pkgname = flag.String("pkg", "main", "Name of the package to generate.")
|
||||
funcname = flag.String("func", "", "Optional name of the function to generate.")
|
||||
prefix = flag.String("prefix", "", "Optional path prefix to strip off map keys and function names.")
|
||||
uncompressed = flag.Bool("uncompressed", false, "The specified resource will /not/ be GZIP compressed when this flag is specified. This alters the generated output code.")
|
||||
nomemcopy = flag.Bool("nomemcopy", false, "Use a .rodata hack to get rid of unnecessary memcopies. Refer to the documentation to see what implications this carries.")
|
||||
tags = flag.String("tags", "", "Optional build tags")
|
||||
toc = flag.Bool("toc", false, "Generate a table of contents for this and other files. The input filepath becomes the map key. This option is only useable in non-pipe mode.")
|
||||
version = flag.Bool("version", false, "Display version information.")
|
||||
)
|
||||
|
||||
func main() {
|
||||
parseArgs()
|
||||
|
||||
if pipe {
|
||||
bindata.Translate(os.Stdin, os.Stdout, *pkgname, *funcname, *uncompressed, *nomemcopy)
|
||||
return
|
||||
}
|
||||
|
||||
fs, err := os.Open(in)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "[e] %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
defer fs.Close()
|
||||
|
||||
fd, err := os.Create(*out)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "[e] %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
defer fd.Close()
|
||||
|
||||
if *tags != "" {
|
||||
fmt.Fprintf(fd, "// +build %s\n\n", *tags)
|
||||
}
|
||||
|
||||
// Translate binary to Go code.
|
||||
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 := bindata.CreateTOC(dir, *pkgname)
|
||||
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "[e] %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
bindata.WriteTOCInit(fd, in, *prefix, *funcname)
|
||||
}
|
||||
}
|
||||
|
||||
// parseArgs processes and verifies commandline arguments.
|
||||
func parseArgs() {
|
||||
flag.Usage = func() {
|
||||
fmt.Printf("Usage: %s [options] <filename>\n\n", os.Args[0])
|
||||
flag.PrintDefaults()
|
||||
}
|
||||
flag.Parse()
|
||||
|
||||
if *version {
|
||||
fmt.Printf("%s\n", bindata.Version())
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
pipe = flag.NArg() == 0
|
||||
|
||||
if !pipe {
|
||||
sepsuffix := strings.HasSuffix(*prefix, string(filepath.Separator))
|
||||
*prefix, _ = filepath.Abs(filepath.Clean(*prefix))
|
||||
if sepsuffix {
|
||||
*prefix += string(filepath.Separator)
|
||||
}
|
||||
in, _ = filepath.Abs(filepath.Clean(flag.Args()[0]))
|
||||
*out = safeFilename(*out, in)
|
||||
}
|
||||
|
||||
if len(*pkgname) == 0 {
|
||||
fmt.Fprintln(os.Stderr, "[w] No package name specified. Using 'main'.")
|
||||
*pkgname = "main"
|
||||
} else {
|
||||
if unicode.IsDigit(rune((*pkgname)[0])) {
|
||||
// Identifier can't start with a digit.
|
||||
*pkgname = "_" + *pkgname
|
||||
}
|
||||
}
|
||||
|
||||
if len(*funcname) == 0 {
|
||||
if pipe {
|
||||
// Can't infer from input file name in this mode.
|
||||
fmt.Fprintln(os.Stderr, "[e] No function name specified.")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
*funcname = bindata.SafeFuncname(in, *prefix)
|
||||
fmt.Fprintf(os.Stderr, "[w] No function name specified. Using %s.\n", *funcname)
|
||||
}
|
||||
}
|
||||
|
||||
// safeFilename creates a safe output filename from the given
|
||||
// output and input paths.
|
||||
func safeFilename(out, in string) string {
|
||||
var filename string
|
||||
|
||||
if len(out) == 0 {
|
||||
filename = in + ".go"
|
||||
|
||||
_, err := os.Lstat(filename)
|
||||
if err == nil {
|
||||
// File already exists. Pad name with a sequential number until we
|
||||
// find a name that is available.
|
||||
count := 0
|
||||
|
||||
for {
|
||||
filename = path.Join(out, fmt.Sprintf("%s.%d.go", in, count))
|
||||
_, err = os.Lstat(filename)
|
||||
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
|
||||
count++
|
||||
}
|
||||
}
|
||||
} else {
|
||||
filename, _ = filepath.Abs(filepath.Clean(out))
|
||||
}
|
||||
|
||||
// Ensure output directory exists while we're here.
|
||||
dir, _ := filepath.Split(filename)
|
||||
_, err := os.Lstat(dir)
|
||||
if err != nil {
|
||||
os.MkdirAll(dir, 0755)
|
||||
}
|
||||
|
||||
return filename
|
||||
}
|
|
@ -0,0 +1,270 @@
|
|||
// This work is subject to the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
|
||||
// license. Its contents can be found at:
|
||||
// http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
package bindata
|
||||
|
||||
import (
|
||||
"compress/gzip"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
)
|
||||
|
||||
// writeRelease writes the release code file.
|
||||
func writeRelease(w io.Writer, c *Config, toc []Asset) error {
|
||||
err := writeReleaseHeader(w, c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for i := range toc {
|
||||
err = writeReleaseAsset(w, c, &toc[i])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// writeReleaseHeader writes output file headers.
|
||||
// This targets release builds.
|
||||
func writeReleaseHeader(w io.Writer, c *Config) error {
|
||||
if c.NoCompress {
|
||||
if c.NoMemCopy {
|
||||
return header_uncompressed_nomemcopy(w)
|
||||
} else {
|
||||
return header_uncompressed_memcopy(w)
|
||||
}
|
||||
} else {
|
||||
if c.NoMemCopy {
|
||||
return header_compressed_nomemcopy(w)
|
||||
} else {
|
||||
return header_compressed_memcopy(w)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// writeReleaseAsset write a release entry for the given asset.
|
||||
// A release entry is a function which embeds and returns
|
||||
// the file's byte content.
|
||||
func writeReleaseAsset(w io.Writer, c *Config, asset *Asset) error {
|
||||
fd, err := os.Open(asset.Path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
defer fd.Close()
|
||||
|
||||
if c.NoCompress {
|
||||
if c.NoMemCopy {
|
||||
return uncompressed_nomemcopy(w, asset, fd)
|
||||
} else {
|
||||
return uncompressed_memcopy(w, asset, fd)
|
||||
}
|
||||
} else {
|
||||
if c.NoMemCopy {
|
||||
return compressed_nomemcopy(w, asset, fd)
|
||||
} else {
|
||||
return compressed_memcopy(w, asset, fd)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func header_compressed_nomemcopy(w io.Writer) error {
|
||||
_, err := fmt.Fprintf(w, `import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"fmt"
|
||||
"io"
|
||||
"reflect"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func bindata_read(data, name string) ([]byte, error) {
|
||||
var empty [0]byte
|
||||
sx := (*reflect.StringHeader)(unsafe.Pointer(&data))
|
||||
b := empty[:]
|
||||
bx := (*reflect.SliceHeader)(unsafe.Pointer(&b))
|
||||
bx.Data = sx.Data
|
||||
bx.Len = len(data)
|
||||
bx.Cap = bx.Len
|
||||
|
||||
gz, err := gzip.NewReader(bytes.NewBuffer(b))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Read %%q: %%v", name, err)
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
_, err = io.Copy(&buf, gz)
|
||||
gz.Close()
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Read %%q: %%v", name, err)
|
||||
}
|
||||
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
`)
|
||||
return err
|
||||
}
|
||||
|
||||
func header_compressed_memcopy(w io.Writer) error {
|
||||
_, err := fmt.Fprintf(w, `import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
func bindata_read(data []byte, name string) ([]byte, error) {
|
||||
gz, err := gzip.NewReader(bytes.NewBuffer(data))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Read %%q: %%v", name, err)
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
_, err = io.Copy(&buf, gz)
|
||||
gz.Close()
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Read %%q: %%v", name, err)
|
||||
}
|
||||
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
`)
|
||||
return err
|
||||
}
|
||||
|
||||
func header_uncompressed_nomemcopy(w io.Writer) error {
|
||||
_, err := fmt.Fprintf(w, `import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func bindata_read(data, name string) ([]byte, error) {
|
||||
var empty [0]byte
|
||||
sx := (*reflect.StringHeader)(unsafe.Pointer(&data))
|
||||
b := empty[:]
|
||||
bx := (*reflect.SliceHeader)(unsafe.Pointer(&b))
|
||||
bx.Data = sx.Data
|
||||
bx.Len = len(data)
|
||||
bx.Cap = bx.Len
|
||||
return b, nil
|
||||
}
|
||||
|
||||
`)
|
||||
return err
|
||||
}
|
||||
|
||||
func header_uncompressed_memcopy(w io.Writer) error {
|
||||
_, err := fmt.Fprintf(w, `import (
|
||||
"fmt"
|
||||
)
|
||||
`)
|
||||
return err
|
||||
}
|
||||
|
||||
func compressed_nomemcopy(w io.Writer, asset *Asset, r io.Reader) error {
|
||||
_, err := fmt.Fprintf(w, `var _%s = "`, asset.Func)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
gz := gzip.NewWriter(&StringWriter{Writer: w})
|
||||
_, err = io.Copy(gz, r)
|
||||
gz.Close()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = fmt.Fprintf(w, `"
|
||||
|
||||
func %s() ([]byte, error) {
|
||||
return bindata_read(
|
||||
_%s,
|
||||
%q,
|
||||
)
|
||||
}
|
||||
|
||||
`, asset.Func, asset.Func, asset.Name)
|
||||
return err
|
||||
}
|
||||
|
||||
func compressed_memcopy(w io.Writer, asset *Asset, r io.Reader) error {
|
||||
_, err := fmt.Fprintf(w, `func %s() ([]byte, error) {
|
||||
return bindata_read([]byte{`, asset.Func)
|
||||
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
gz := gzip.NewWriter(&ByteWriter{Writer: w})
|
||||
_, err = io.Copy(gz, r)
|
||||
gz.Close()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = fmt.Fprintf(w, `
|
||||
},
|
||||
%q,
|
||||
)
|
||||
}
|
||||
|
||||
`, asset.Name)
|
||||
return err
|
||||
}
|
||||
|
||||
func uncompressed_nomemcopy(w io.Writer, asset *Asset, r io.Reader) error {
|
||||
_, err := fmt.Fprintf(w, `var _%s = "`, asset.Func)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = io.Copy(&StringWriter{Writer: w}, r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = fmt.Fprintf(w, `"
|
||||
|
||||
func %s() ([]byte, error) {
|
||||
return bindata_read(
|
||||
_%s,
|
||||
%q,
|
||||
)
|
||||
}
|
||||
|
||||
`, asset.Func, asset.Func, asset.Name)
|
||||
return err
|
||||
}
|
||||
|
||||
func uncompressed_memcopy(w io.Writer, asset *Asset, r io.Reader) error {
|
||||
_, err := fmt.Fprintf(w, `func %s() ([]byte, error) {
|
||||
return []byte{`, asset.Func)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = io.Copy(&ByteWriter{Writer: w}, r)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = fmt.Fprintf(w, `
|
||||
}, nil
|
||||
}
|
||||
|
||||
`)
|
||||
return err
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package main
|
||||
|
||||
// Global Table of Contents map. Generated by go-bindata.
|
||||
// After startup of the program, all generated data files will
|
||||
// put themselves in this map. The key is the full filename, as
|
||||
// supplied to go-bindata.
|
||||
var go_bindata = make(map[string]func() []byte)
|
Binary file not shown.
Before Width: | Height: | Size: 21 KiB |
|
@ -0,0 +1 @@
|
|||
// sample file
|
|
@ -0,0 +1 @@
|
|||
// sample file
|
|
@ -0,0 +1 @@
|
|||
// sample file
|
|
@ -0,0 +1 @@
|
|||
// sample file
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,86 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"io"
|
||||
"log"
|
||||
)
|
||||
|
||||
func bindata_read(data []byte, name string) []byte {
|
||||
gz, err := gzip.NewReader(bytes.NewBuffer(data))
|
||||
if err != nil {
|
||||
log.Fatalf("Read %q: %v", name, err)
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
_, err = io.Copy(&buf, gz)
|
||||
gz.Close()
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("Read %q: %v", name, err)
|
||||
}
|
||||
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
func in_b_test_asset() []byte {
|
||||
return bindata_read([]byte{
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x00, 0xff, 0xd2, 0xd7,
|
||||
0x57, 0x28, 0x4e, 0xcc, 0x2d, 0xc8, 0x49, 0x55, 0x48, 0xcb, 0xcc, 0x49,
|
||||
0xe5, 0x02, 0x04, 0x00, 0x00, 0xff, 0xff, 0x8a, 0x82, 0x8c, 0x85, 0x0f,
|
||||
0x00, 0x00, 0x00,
|
||||
},
|
||||
"in/b/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
func in_test_asset() []byte {
|
||||
return bindata_read([]byte{
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x00, 0xff, 0xd2, 0xd7,
|
||||
0x57, 0x28, 0x4e, 0xcc, 0x2d, 0xc8, 0x49, 0x55, 0x48, 0xcb, 0xcc, 0x49,
|
||||
0xe5, 0x02, 0x04, 0x00, 0x00, 0xff, 0xff, 0x8a, 0x82, 0x8c, 0x85, 0x0f,
|
||||
0x00, 0x00, 0x00,
|
||||
},
|
||||
"in/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
func in_a_test_asset() []byte {
|
||||
return bindata_read([]byte{
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x00, 0xff, 0xd2, 0xd7,
|
||||
0x57, 0x28, 0x4e, 0xcc, 0x2d, 0xc8, 0x49, 0x55, 0x48, 0xcb, 0xcc, 0x49,
|
||||
0xe5, 0x02, 0x04, 0x00, 0x00, 0xff, 0xff, 0x8a, 0x82, 0x8c, 0x85, 0x0f,
|
||||
0x00, 0x00, 0x00,
|
||||
},
|
||||
"in/a/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
func in_c_test_asset() []byte {
|
||||
return bindata_read([]byte{
|
||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x00, 0xff, 0xd2, 0xd7,
|
||||
0x57, 0x28, 0x4e, 0xcc, 0x2d, 0xc8, 0x49, 0x55, 0x48, 0xcb, 0xcc, 0x49,
|
||||
0xe5, 0x02, 0x04, 0x00, 0x00, 0xff, 0xff, 0x8a, 0x82, 0x8c, 0x85, 0x0f,
|
||||
0x00, 0x00, 0x00,
|
||||
},
|
||||
"in/c/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
// Asset loads and returns the asset for the given name.
|
||||
// This returns nil of the asset could not be found.
|
||||
func Asset(name string) []byte {
|
||||
if f, ok := _bindata[name]; ok {
|
||||
return f()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||
var _bindata = map[string]func() []byte{
|
||||
"in/b/test.asset": in_b_test_asset,
|
||||
"in/test.asset": in_test_asset,
|
||||
"in/a/test.asset": in_a_test_asset,
|
||||
"in/c/test.asset": in_c_test_asset,
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"io"
|
||||
"log"
|
||||
"reflect"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func bindata_read(data, name string) []byte {
|
||||
var empty [0]byte
|
||||
sx := (*reflect.StringHeader)(unsafe.Pointer(&data))
|
||||
b := empty[:]
|
||||
bx := (*reflect.SliceHeader)(unsafe.Pointer(&b))
|
||||
bx.Data = sx.Data
|
||||
bx.Len = len(data)
|
||||
bx.Cap = bx.Len
|
||||
|
||||
gz, err := gzip.NewReader(bytes.NewBuffer(b))
|
||||
if err != nil {
|
||||
log.Fatalf("Read %q: %v", name, err)
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
_, err = io.Copy(&buf, gz)
|
||||
gz.Close()
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("Read %q: %v", name, err)
|
||||
}
|
||||
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
var _in_b_test_asset = "\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xd2\xd7\x57\x28\x4e\xcc\x2d\xc8\x49\x55\x48\xcb\xcc\x49\xe5\x02\x04\x00\x00\xff\xff\x8a\x82\x8c\x85\x0f\x00\x00\x00"
|
||||
|
||||
func in_b_test_asset() []byte {
|
||||
return bindata_read(
|
||||
_in_b_test_asset,
|
||||
"in/b/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
var _in_test_asset = "\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xd2\xd7\x57\x28\x4e\xcc\x2d\xc8\x49\x55\x48\xcb\xcc\x49\xe5\x02\x04\x00\x00\xff\xff\x8a\x82\x8c\x85\x0f\x00\x00\x00"
|
||||
|
||||
func in_test_asset() []byte {
|
||||
return bindata_read(
|
||||
_in_test_asset,
|
||||
"in/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
var _in_a_test_asset = "\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xd2\xd7\x57\x28\x4e\xcc\x2d\xc8\x49\x55\x48\xcb\xcc\x49\xe5\x02\x04\x00\x00\xff\xff\x8a\x82\x8c\x85\x0f\x00\x00\x00"
|
||||
|
||||
func in_a_test_asset() []byte {
|
||||
return bindata_read(
|
||||
_in_a_test_asset,
|
||||
"in/a/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
var _in_c_test_asset = "\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xd2\xd7\x57\x28\x4e\xcc\x2d\xc8\x49\x55\x48\xcb\xcc\x49\xe5\x02\x04\x00\x00\xff\xff\x8a\x82\x8c\x85\x0f\x00\x00\x00"
|
||||
|
||||
func in_c_test_asset() []byte {
|
||||
return bindata_read(
|
||||
_in_c_test_asset,
|
||||
"in/c/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
// Asset loads and returns the asset for the given name.
|
||||
// This returns nil of the asset could not be found.
|
||||
func Asset(name string) []byte {
|
||||
if f, ok := _bindata[name]; ok {
|
||||
return f()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||
var _bindata = map[string]func() []byte{
|
||||
"in/b/test.asset": in_b_test_asset,
|
||||
"in/test.asset": in_test_asset,
|
||||
"in/a/test.asset": in_a_test_asset,
|
||||
"in/c/test.asset": in_c_test_asset,
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
// bindata_read reads the given file from disk.
|
||||
// It panics if anything went wrong.
|
||||
func bindata_read(path, name string) []byte {
|
||||
fd, err := os.Open(path)
|
||||
if err != nil {
|
||||
log.Fatalf("Read %s: %v", name, err)
|
||||
}
|
||||
|
||||
defer fd.Close()
|
||||
|
||||
var buf bytes.Buffer
|
||||
_, err = io.Copy(&buf, fd)
|
||||
if err != nil {
|
||||
log.Fatalf("Read %s: %v", name, err)
|
||||
}
|
||||
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
// in_b_test_asset reads file data from disk.
|
||||
// It panics if something went wrong in the process.
|
||||
func in_b_test_asset() []byte {
|
||||
return bindata_read(
|
||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/b/test.asset",
|
||||
"in/b/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
// in_test_asset reads file data from disk.
|
||||
// It panics if something went wrong in the process.
|
||||
func in_test_asset() []byte {
|
||||
return bindata_read(
|
||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/test.asset",
|
||||
"in/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
// in_a_test_asset reads file data from disk.
|
||||
// It panics if something went wrong in the process.
|
||||
func in_a_test_asset() []byte {
|
||||
return bindata_read(
|
||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/a/test.asset",
|
||||
"in/a/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
// in_c_test_asset reads file data from disk.
|
||||
// It panics if something went wrong in the process.
|
||||
func in_c_test_asset() []byte {
|
||||
return bindata_read(
|
||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/c/test.asset",
|
||||
"in/c/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
// Asset loads and returns the asset for the given name.
|
||||
// This returns nil of the asset could not be found.
|
||||
func Asset(name string) []byte {
|
||||
if f, ok := _bindata[name]; ok {
|
||||
return f()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||
var _bindata = map[string]func() []byte{
|
||||
"in/b/test.asset": in_b_test_asset,
|
||||
"in/test.asset": in_test_asset,
|
||||
"in/a/test.asset": in_a_test_asset,
|
||||
"in/c/test.asset": in_c_test_asset,
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package main
|
||||
|
||||
func in_b_test_asset() []byte {
|
||||
return []byte{
|
||||
0x2f, 0x2f, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x66, 0x69,
|
||||
0x6c, 0x65, 0x0a,
|
||||
}
|
||||
}
|
||||
|
||||
func in_test_asset() []byte {
|
||||
return []byte{
|
||||
0x2f, 0x2f, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x66, 0x69,
|
||||
0x6c, 0x65, 0x0a,
|
||||
}
|
||||
}
|
||||
|
||||
func in_a_test_asset() []byte {
|
||||
return []byte{
|
||||
0x2f, 0x2f, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x66, 0x69,
|
||||
0x6c, 0x65, 0x0a,
|
||||
}
|
||||
}
|
||||
|
||||
func in_c_test_asset() []byte {
|
||||
return []byte{
|
||||
0x2f, 0x2f, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x66, 0x69,
|
||||
0x6c, 0x65, 0x0a,
|
||||
}
|
||||
}
|
||||
|
||||
// Asset loads and returns the asset for the given name.
|
||||
// This returns nil of the asset could not be found.
|
||||
func Asset(name string) []byte {
|
||||
if f, ok := _bindata[name]; ok {
|
||||
return f()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||
var _bindata = map[string]func() []byte{
|
||||
"in/b/test.asset": in_b_test_asset,
|
||||
"in/test.asset": in_test_asset,
|
||||
"in/a/test.asset": in_a_test_asset,
|
||||
"in/c/test.asset": in_c_test_asset,
|
||||
}
|
|
@ -0,0 +1,70 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
func bindata_read(data, name string) []byte {
|
||||
var empty [0]byte
|
||||
sx := (*reflect.StringHeader)(unsafe.Pointer(&data))
|
||||
b := empty[:]
|
||||
bx := (*reflect.SliceHeader)(unsafe.Pointer(&b))
|
||||
bx.Data = sx.Data
|
||||
bx.Len = len(data)
|
||||
bx.Cap = bx.Len
|
||||
return b
|
||||
}
|
||||
|
||||
var _in_b_test_asset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a"
|
||||
|
||||
func in_b_test_asset() []byte {
|
||||
return bindata_read(
|
||||
_in_b_test_asset,
|
||||
"in/b/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
var _in_test_asset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a"
|
||||
|
||||
func in_test_asset() []byte {
|
||||
return bindata_read(
|
||||
_in_test_asset,
|
||||
"in/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
var _in_a_test_asset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a"
|
||||
|
||||
func in_a_test_asset() []byte {
|
||||
return bindata_read(
|
||||
_in_a_test_asset,
|
||||
"in/a/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
var _in_c_test_asset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a"
|
||||
|
||||
func in_c_test_asset() []byte {
|
||||
return bindata_read(
|
||||
_in_c_test_asset,
|
||||
"in/c/test.asset",
|
||||
)
|
||||
}
|
||||
|
||||
// Asset loads and returns the asset for the given name.
|
||||
// This returns nil of the asset could not be found.
|
||||
func Asset(name string) []byte {
|
||||
if f, ok := _bindata[name]; ok {
|
||||
return f()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||
var _bindata = map[string]func() []byte{
|
||||
"in/b/test.asset": in_b_test_asset,
|
||||
"in/test.asset": in_test_asset,
|
||||
"in/a/test.asset": in_a_test_asset,
|
||||
"in/c/test.asset": in_c_test_asset,
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,60 @@
|
|||
// This work is subject to the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
|
||||
// license. Its contents can be found at:
|
||||
// http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
package bindata
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
// writeTOC writes the table of contents file.
|
||||
func writeTOC(w io.Writer, toc []Asset) error {
|
||||
err := writeTOCHeader(w)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for i := range toc {
|
||||
err = writeTOCAsset(w, &toc[i])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return writeTOCFooter(w)
|
||||
}
|
||||
|
||||
// writeTOCHeader writes the table of contents file header.
|
||||
func writeTOCHeader(w io.Writer) error {
|
||||
_, err := fmt.Fprintf(w, `
|
||||
// Asset loads and returns the asset for the given name.
|
||||
// It returns an error if the asset could not be found or
|
||||
// could not be loaded.
|
||||
func Asset(name string) ([]byte, error) {
|
||||
if f, ok := _bindata[name]; ok {
|
||||
return f()
|
||||
}
|
||||
return nil, fmt.Errorf("Asset %%s not found", name)
|
||||
}
|
||||
|
||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||
var _bindata = map[string] func() ([]byte, error) {
|
||||
`)
|
||||
return err
|
||||
}
|
||||
|
||||
// writeTOCAsset write a TOC entry for the given asset.
|
||||
func writeTOCAsset(w io.Writer, asset *Asset) error {
|
||||
_, err := fmt.Fprintf(w, "\t%q: %s,\n", asset.Name, asset.Func)
|
||||
return err
|
||||
}
|
||||
|
||||
// writeTOCFooter writes the table of contents file footer.
|
||||
func writeTOCFooter(w io.Writer) error {
|
||||
_, err := fmt.Fprintf(w, `
|
||||
}
|
||||
`)
|
||||
return err
|
||||
}
|
Loading…
Reference in New Issue