Compare commits
140 Commits
Author | SHA1 | Date | |
---|---|---|---|
7816a8a362 | |||
|
6025e8de66 | ||
|
a0ff2567cf | ||
|
8ed2cd0f6d | ||
|
bfe36d3254 | ||
|
7f4fb1184f | ||
|
dce55d09e2 | ||
|
57e5327e97 | ||
|
19c9a00bca | ||
|
96e3c9c230 | ||
|
14ba83ac84 | ||
|
94e9e44a67 | ||
|
281d36d28b | ||
|
0e7bf08e91 | ||
|
564900b991 | ||
|
c2c7562055 | ||
|
2026467100 | ||
|
bd8da9c54b | ||
|
38ae5514e6 | ||
|
ff362dd1f1 | ||
|
91db54b040 | ||
|
49f71bc21c | ||
|
eb723d5626 | ||
|
6a532a6d90 | ||
|
83a44d533b | ||
|
a4f78e909c | ||
|
3ad80867de | ||
|
1788809334 | ||
|
b0c5bef59f | ||
|
ca29b0b7f5 | ||
|
69db088dee | ||
|
36d53ead3a | ||
|
e01811006d | ||
|
eb01a153be | ||
|
dfcf23b04e | ||
|
4fc85e2b3c | ||
|
dada32c78b | ||
|
6b468a429a | ||
|
ba26659a34 | ||
|
4f258b3140 | ||
|
ffff253524 | ||
|
4d36d97d1d | ||
|
d0a5f1749d | ||
|
fff92e7dec | ||
|
a15f234cb1 | ||
|
c3e4c77465 | ||
|
476077970b | ||
|
76a6418a0a | ||
|
465fc29db9 | ||
|
f449dcd26c | ||
|
1d06945605 | ||
|
21f0a65fc5 | ||
|
9178943e13 | ||
|
7362d4b6b2 | ||
|
b5d9eff767 | ||
|
040617c5ef | ||
|
81e20ed1b7 | ||
|
8ee21af0fa | ||
|
af127dc2da | ||
|
8ec170e704 | ||
|
0efad67aa4 | ||
|
4a8e91e5cd | ||
|
e3850a4b3c | ||
|
452770b024 | ||
|
f80b50711d | ||
|
7159dbfa31 | ||
|
fc595e391e | ||
|
f7b87a0a9a | ||
|
0267f6e673 | ||
|
9091c617ee | ||
|
5dec5f37be | ||
|
f9f833bc6e | ||
|
f94581bd91 | ||
|
fcbedc59d6 | ||
|
bbd0c6e271 | ||
|
2c5bf09f1b | ||
|
da92400a92 | ||
|
0e05e3a19d | ||
|
1796683e4d | ||
|
8f6e0a3425 | ||
|
1743f47c01 | ||
|
853793af8f | ||
|
93b909d149 | ||
|
cfd1b4bd08 | ||
|
64e31e0c92 | ||
|
6ca6b73691 | ||
|
388b47b5ff | ||
|
6347e7a31c | ||
|
b040f60a8c | ||
|
68a53ac0c2 | ||
|
c3d7350481 | ||
|
d47bbf733e | ||
|
54e5992f47 | ||
|
c15090e68a | ||
|
d3feb9534c | ||
|
17800c65a0 | ||
|
394d5b27c0 | ||
|
f93f031745 | ||
|
4b70a41eb8 | ||
|
ff2ab748eb | ||
|
8abc1cae37 | ||
|
e764a84fdf | ||
|
57a8ec74ce | ||
|
6c168add63 | ||
|
ab3c8e2995 | ||
|
cda5f335ae | ||
|
ca7033b19a | ||
|
2ebf002fb5 | ||
|
7f6fddddd0 | ||
|
212d2a5cdc | ||
|
3834e2fe48 | ||
|
362b0784bb | ||
|
eb1b26017a | ||
|
1c1928d3b6 | ||
|
e87a807885 | ||
|
ae22b84b7e | ||
|
436fd0c250 | ||
|
7d4f92315c | ||
|
f628643380 | ||
|
658f2bddf4 | ||
|
bb0b560542 | ||
|
20077324b7 | ||
|
4bf44a02f1 | ||
|
85c2b05609 | ||
|
37aa0dc02e | ||
|
28919a6a56 | ||
|
7bd7bcfcdf | ||
|
b903585359 | ||
|
4674192d6b | ||
|
14a0ff90f8 | ||
|
67221add2e | ||
|
f43e6bd89c | ||
|
bd1a47dfea | ||
|
8e87ecda2a | ||
|
7ab45c816f | ||
|
2c7ab48825 | ||
|
965fbe401b | ||
|
b1eab644d7 | ||
|
ca6a684780 | ||
|
f5e037a829 |
79
CONTRIBUTING.md
Normal file
79
CONTRIBUTING.md
Normal file
|
@ -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 choose 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.
|
||||||
|
|
||||||
|
|
11
CONTRIBUTORS
11
CONTRIBUTORS
|
@ -1,11 +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.
|
|
||||||
|
|
||||||
Alan Shreve <alan@inconshreveable.com>
|
|
||||||
Jim Teeuwen <jimteeuwen at gmail dot com>
|
|
63
README.md
63
README.md
|
@ -1,3 +1,13 @@
|
||||||
|
> **NOTICE:**
|
||||||
|
>
|
||||||
|
> This repository is a fork of <https://github.com/jteeuwen/go-bindata> which
|
||||||
|
> itself was a fork of an original project that disappeared.
|
||||||
|
>
|
||||||
|
> I've cloned a copy for personal use at <https://git.kirsle.net/go/bindata> so
|
||||||
|
> that I always have a version that won't disappear.
|
||||||
|
>
|
||||||
|
> [@kirsle](https://www.kirsle.net/)
|
||||||
|
|
||||||
## bindata
|
## bindata
|
||||||
|
|
||||||
This package converts any file into managable Go source code. Useful for
|
This package converts any file into managable Go source code. Useful for
|
||||||
|
@ -9,9 +19,16 @@ This tool offers a set of command line options, used to customize the
|
||||||
output being generated.
|
output being generated.
|
||||||
|
|
||||||
|
|
||||||
|
### Installation
|
||||||
|
|
||||||
|
To install the library and command line program, use the following:
|
||||||
|
|
||||||
|
go get -u git.kirsle.net/go/bindata/...
|
||||||
|
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
Conversion is done on a set of files. They are all embedded in a new
|
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,
|
Go source file, along with a table of contents and an `Asset` function,
|
||||||
which allows quick access to the asset, based on its name.
|
which allows quick access to the asset, based on its name.
|
||||||
|
|
||||||
|
@ -20,20 +37,41 @@ working directory. It includes all assets from the `data` directory.
|
||||||
|
|
||||||
$ go-bindata data/
|
$ go-bindata data/
|
||||||
|
|
||||||
To include all input sub-directories recursively, add the `-r` flag,
|
To include all input sub-directories recursively, use the elipsis postfix
|
||||||
otherwise it will only consider files in the input directory itself.
|
as defined for Go import paths. Otherwise it will only consider assets in the
|
||||||
|
input directory itself.
|
||||||
|
|
||||||
$ go-bindata -r data/
|
$ go-bindata data/...
|
||||||
|
|
||||||
To specify the name of the output file being generated, we use the following:
|
To specify the name of the output file being generated, we use the following:
|
||||||
|
|
||||||
$ go-bindata data/ myfile.go
|
$ go-bindata -o myfile.go data/
|
||||||
|
|
||||||
The following paragraphs detail some of the command line options which can
|
Multiple input directories can be specified if necessary.
|
||||||
supplied to `go-bindata`.
|
|
||||||
|
|
||||||
Refer to the `testdata/out` directory for various output examples from
|
$ go-bindata dir1/... /path/to/dir2/... dir3
|
||||||
the assets in `testdata/in`. Each example uses different command line options.
|
|
||||||
|
|
||||||
|
The following paragraphs detail some of the command line options which can be
|
||||||
|
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.
|
||||||
|
|
||||||
|
To ignore files, pass in regexes using -ignore, for example:
|
||||||
|
|
||||||
|
$ go-bindata -ignore=\\.gitignore data/...
|
||||||
|
|
||||||
|
### Accessing an asset
|
||||||
|
|
||||||
|
To access asset data, we use the `Asset(string) ([]byte, error)` function which
|
||||||
|
is included in the generated output.
|
||||||
|
|
||||||
|
data, err := Asset("pub/style/foo.css")
|
||||||
|
if err != nil {
|
||||||
|
// Asset was not found.
|
||||||
|
}
|
||||||
|
|
||||||
|
// use asset data
|
||||||
|
|
||||||
|
|
||||||
### Debug vs Release builds
|
### Debug vs Release builds
|
||||||
|
@ -122,7 +160,7 @@ even increase the size of the data.
|
||||||
The default behaviour of the program is to use compression.
|
The default behaviour of the program is to use compression.
|
||||||
|
|
||||||
|
|
||||||
#### Path prefix stripping
|
### Path prefix stripping
|
||||||
|
|
||||||
The keys used in the `_bindata` map, are the same as the input file name
|
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
|
passed to `go-bindata`. This includes the path. In most cases, this is not
|
||||||
|
@ -144,7 +182,7 @@ Running with the `-prefix` flag, we get:
|
||||||
_bindata["templates/foo.html"] = templates_foo_html
|
_bindata["templates/foo.html"] = templates_foo_html
|
||||||
|
|
||||||
|
|
||||||
#### Build tags
|
### 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
|
must be fulfilled for the output file to be included in a build. This
|
||||||
|
@ -154,4 +192,7 @@ 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
|
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.
|
and must follow the build tags syntax specified by the go tool.
|
||||||
|
|
||||||
|
### Related projects
|
||||||
|
|
||||||
|
[go-bindata-assetfs](https://github.com/elazarl/go-bindata-assetfs#readme) -
|
||||||
|
implements `http.FileSystem` interface. Allows you to serve assets with `net/http`.
|
||||||
|
|
|
@ -9,7 +9,11 @@ import (
|
||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
var newline = []byte{'\n'}
|
var (
|
||||||
|
newline = []byte{'\n'}
|
||||||
|
dataindent = []byte{'\t', '\t'}
|
||||||
|
space = []byte{' '}
|
||||||
|
)
|
||||||
|
|
||||||
type ByteWriter struct {
|
type ByteWriter struct {
|
||||||
io.Writer
|
io.Writer
|
||||||
|
@ -24,7 +28,10 @@ func (w *ByteWriter) Write(p []byte) (n int, err error) {
|
||||||
for n = range p {
|
for n = range p {
|
||||||
if w.c%12 == 0 {
|
if w.c%12 == 0 {
|
||||||
w.Writer.Write(newline)
|
w.Writer.Write(newline)
|
||||||
|
w.Writer.Write(dataindent)
|
||||||
w.c = 0
|
w.c = 0
|
||||||
|
} else {
|
||||||
|
w.Writer.Write(space)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintf(w.Writer, "0x%02x,", p[n])
|
fmt.Fprintf(w.Writer, "0x%02x,", p[n])
|
||||||
|
|
196
config.go
196
config.go
|
@ -8,8 +8,20 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 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.
|
// Config defines a set of options for the asset conversion.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
// Name of the package to use. Defaults to 'main'.
|
// Name of the package to use. Defaults to 'main'.
|
||||||
|
@ -21,84 +33,77 @@ type Config struct {
|
||||||
// and must follow the build tags syntax specified by the go tool.
|
// and must follow the build tags syntax specified by the go tool.
|
||||||
Tags string
|
Tags string
|
||||||
|
|
||||||
// Input defines the directory path, containing all asset files.
|
// Input defines the directory path, containing all asset files as
|
||||||
// This may contain sub directories, which will be included in the
|
// well as whether to recursively process assets in any sub directories.
|
||||||
// conversion.
|
Input []InputConfig
|
||||||
Input string
|
|
||||||
|
|
||||||
// Output defines the output file for the generated code.
|
// Output defines the output file for the generated code.
|
||||||
// If left empty, this defaults to 'bindata.go' in the current
|
// If left empty, this defaults to 'bindata.go' in the current
|
||||||
// working directory.
|
// working directory.
|
||||||
Output string
|
Output string
|
||||||
|
|
||||||
/*
|
// Prefix defines a path prefix which should be stripped from all
|
||||||
Prefix defines a path prefix which should be stripped from all
|
// file names when generating the keys in the table of contents.
|
||||||
file names when generating the keys in the table of contents.
|
// For example, running without the `-prefix` flag, we get:
|
||||||
For example, running without the `-prefix` flag, we get:
|
//
|
||||||
|
// $ go-bindata /path/to/templates
|
||||||
$ go-bindata /path/to/templates
|
// go_bindata["/path/to/templates/foo.html"] = _path_to_templates_foo_html
|
||||||
go_bindata["/path/to/templates/foo.html"] = _path_to_templates_foo_html
|
//
|
||||||
|
// Running with the `-prefix` flag, we get:
|
||||||
Running with the `-prefix` flag, we get:
|
//
|
||||||
|
// $ go-bindata -prefix "/path/to/" /path/to/templates/foo.html
|
||||||
$ go-bindata -prefix "/path/to/" /path/to/templates/foo.html
|
// go_bindata["templates/foo.html"] = templates_foo_html
|
||||||
go_bindata["templates/foo.html"] = templates_foo_html
|
|
||||||
*/
|
|
||||||
Prefix string
|
Prefix string
|
||||||
|
|
||||||
/*
|
// NoMemCopy will alter the way the output file is generated.
|
||||||
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
|
||||||
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
|
||||||
the compiled program's `.rodata` section. This ensures that when we call
|
// call our generated function, we omit unnecessary mem copies.
|
||||||
call our generated function, we omit unnecessary mem copies.
|
//
|
||||||
|
// The downside of this, is that it requires dependencies on the `reflect` and
|
||||||
The downside of this, is that it requires dependencies on the `reflect` and
|
// `unsafe` packages. These may be restricted on platforms like AppEngine and
|
||||||
`unsafe` packages. These may be restricted on platforms like AppEngine and
|
// thus prevent you from using this mode.
|
||||||
thus prevent you from using this mode.
|
//
|
||||||
|
// Another disadvantage is that the byte slice we create, is strictly read-only.
|
||||||
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
|
||||||
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
|
||||||
returned byte slice, a runtime panic is thrown. Use this mode only on target
|
// platforms where memory constraints are an issue.
|
||||||
platforms where memory constraints are an issue.
|
//
|
||||||
|
// The default behaviour is to use the old code generation method. This
|
||||||
The default behaviour is to use the old code generation method. This
|
// prevents the two previously mentioned issues, but will employ at least one
|
||||||
prevents the two previously mentioned issues, but will employ at least one
|
// extra memcopy and thus increase memory requirements.
|
||||||
extra memcopy and thus increase memory requirements.
|
//
|
||||||
|
// For instance, consider the following two examples:
|
||||||
For instance, consider the following two examples:
|
//
|
||||||
|
// This would be the default mode, using an extra memcopy but gives a safe
|
||||||
This would be the default mode, using an extra memcopy but gives a safe
|
// implementation without dependencies on `reflect` and `unsafe`:
|
||||||
implementation without dependencies on `reflect` and `unsafe`:
|
//
|
||||||
|
// func myfile() []byte {
|
||||||
func myfile() []byte {
|
// return []byte{0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a}
|
||||||
return []byte{0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a}
|
// }
|
||||||
}
|
//
|
||||||
|
// Here is the same functionality, but uses the `.rodata` hack.
|
||||||
Here is the same functionality, but uses the `.rodata` hack.
|
// The byte slice returned from this example can not be written to without
|
||||||
The byte slice returned from this example can not be written to without
|
// generating a runtime error.
|
||||||
generating a runtime error.
|
//
|
||||||
|
// var _myfile = "\x89\x50\x4e\x47\x0d\x0a\x1a"
|
||||||
var _myfile = "\x89\x50\x4e\x47\x0d\x0a\x1a"
|
//
|
||||||
|
// func myfile() []byte {
|
||||||
func myfile() []byte {
|
// var empty [0]byte
|
||||||
var empty [0]byte
|
// sx := (*reflect.StringHeader)(unsafe.Pointer(&_myfile))
|
||||||
sx := (*reflect.StringHeader)(unsafe.Pointer(&_myfile))
|
// b := empty[:]
|
||||||
b := empty[:]
|
// bx := (*reflect.SliceHeader)(unsafe.Pointer(&b))
|
||||||
bx := (*reflect.SliceHeader)(unsafe.Pointer(&b))
|
// bx.Data = sx.Data
|
||||||
bx.Data = sx.Data
|
// bx.Len = len(_myfile)
|
||||||
bx.Len = len(_myfile)
|
// bx.Cap = bx.Len
|
||||||
bx.Cap = bx.Len
|
// return b
|
||||||
return b
|
// }
|
||||||
}
|
|
||||||
*/
|
|
||||||
NoMemCopy bool
|
NoMemCopy bool
|
||||||
|
|
||||||
/*
|
// NoCompress means the assets are /not/ GZIP compressed before being turned
|
||||||
NoCompress means the assets are /not/ GZIP compressed before being turned
|
// into Go code. The generated function will automatically unzip
|
||||||
into Go code. The generated function will automatically unzip
|
// the file data when called. Defaults to false.
|
||||||
the file data when called. Defaults to true.
|
|
||||||
*/
|
|
||||||
NoCompress bool
|
NoCompress bool
|
||||||
|
|
||||||
// Perform a debug build. This generates an asset file, which
|
// Perform a debug build. This generates an asset file, which
|
||||||
|
@ -112,10 +117,29 @@ type Config struct {
|
||||||
// in the code. The default behaviour is Release mode.
|
// in the code. The default behaviour is Release mode.
|
||||||
Debug bool
|
Debug bool
|
||||||
|
|
||||||
// Recursively process all assets in the input directory and its
|
// Perform a dev build, which is nearly identical to the debug option. The
|
||||||
// sub directories. This defaults to false, so only files in the
|
// only difference is that instead of absolute file paths in generated code,
|
||||||
// input directory itself are read.
|
// it expects a variable, `rootDir`, to be set in the generated code's
|
||||||
Recursive bool
|
// package (the author needs to do this manually), which it then prepends to
|
||||||
|
// an asset's name to construct the file path on disk.
|
||||||
|
//
|
||||||
|
// This is mainly so you can push the generated code file to a shared
|
||||||
|
// repository.
|
||||||
|
Dev bool
|
||||||
|
|
||||||
|
// When true, size, mode and modtime are not preserved from files
|
||||||
|
NoMetadata bool
|
||||||
|
// When nonzero, use this as mode for all files.
|
||||||
|
Mode uint
|
||||||
|
// When nonzero, use this as unix timestamp for all files.
|
||||||
|
ModTime int64
|
||||||
|
|
||||||
|
// Ignores any filenames matching the regex pattern specified, e.g.
|
||||||
|
// path/to/file.ext will ignore only that file, or \\.gitignore
|
||||||
|
// will match any .gitignore file.
|
||||||
|
//
|
||||||
|
// This parameter can be provided multiple times.
|
||||||
|
Ignore []*regexp.Regexp
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewConfig returns a default configuration struct.
|
// NewConfig returns a default configuration struct.
|
||||||
|
@ -125,7 +149,8 @@ func NewConfig() *Config {
|
||||||
c.NoMemCopy = false
|
c.NoMemCopy = false
|
||||||
c.NoCompress = false
|
c.NoCompress = false
|
||||||
c.Debug = false
|
c.Debug = false
|
||||||
c.Recursive = false
|
c.Output = "./bindata.go"
|
||||||
|
c.Ignore = make([]*regexp.Regexp, 0)
|
||||||
return c
|
return c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,13 +161,11 @@ func (c *Config) validate() error {
|
||||||
return fmt.Errorf("Missing package name")
|
return fmt.Errorf("Missing package name")
|
||||||
}
|
}
|
||||||
|
|
||||||
stat, err := os.Lstat(c.Input)
|
for _, input := range c.Input {
|
||||||
|
_, err := os.Lstat(input.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("Input path: %v", err)
|
return fmt.Errorf("Failed to stat input path '%s': %v", input.Path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !stat.IsDir() {
|
|
||||||
return fmt.Errorf("Input path is not a directory.")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(c.Output) == 0 {
|
if len(c.Output) == 0 {
|
||||||
|
@ -154,11 +177,24 @@ func (c *Config) validate() error {
|
||||||
c.Output = filepath.Join(cwd, "bindata.go")
|
c.Output = filepath.Join(cwd, "bindata.go")
|
||||||
}
|
}
|
||||||
|
|
||||||
stat, err = os.Lstat(c.Output)
|
stat, err := os.Lstat(c.Output)
|
||||||
if err != nil && !os.IsNotExist(err) {
|
if err != nil {
|
||||||
|
if !os.IsNotExist(err) {
|
||||||
return fmt.Errorf("Output path: %v", 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)
|
||||||
|
if dir != "" {
|
||||||
|
err = os.MkdirAll(dir, 0744)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("Create output directory: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if stat != nil && stat.IsDir() {
|
if stat != nil && stat.IsDir() {
|
||||||
return fmt.Errorf("Output path is a directory.")
|
return fmt.Errorf("Output path is a directory.")
|
||||||
}
|
}
|
||||||
|
|
179
convert.go
179
convert.go
|
@ -5,16 +5,18 @@
|
||||||
package bindata
|
package bindata
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"sort"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Translate reads assets from an input directory, converts them
|
// Translate reads assets from an input directory, converts them
|
||||||
// to Go code and writes new files to the output file specified
|
// to Go code and writes new files to the output specified
|
||||||
// in the given configuration.
|
// in the given configuration.
|
||||||
func Translate(c *Config) error {
|
func Translate(c *Config) error {
|
||||||
var toc []Asset
|
var toc []Asset
|
||||||
|
@ -25,11 +27,15 @@ func Translate(c *Config) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var knownFuncs = make(map[string]int)
|
||||||
|
var visitedPaths = make(map[string]bool)
|
||||||
// Locate all the assets.
|
// Locate all the assets.
|
||||||
err = findFiles(c.Input, c.Prefix, c.Recursive, &toc)
|
for _, input := range c.Input {
|
||||||
|
err = findFiles(input.Path, c.Prefix, input.Recursive, &toc, c.Ignore, knownFuncs, visitedPaths)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Create output file.
|
// Create output file.
|
||||||
fd, err := os.Create(c.Output)
|
fd, err := os.Create(c.Output)
|
||||||
|
@ -39,25 +45,51 @@ func Translate(c *Config) error {
|
||||||
|
|
||||||
defer fd.Close()
|
defer fd.Close()
|
||||||
|
|
||||||
|
// Create a buffered writer for better performance.
|
||||||
|
bfd := bufio.NewWriter(fd)
|
||||||
|
defer bfd.Flush()
|
||||||
|
|
||||||
|
// Write the header. This makes e.g. Github ignore diffs in generated files.
|
||||||
|
if _, err = fmt.Fprint(bfd, "// Code generated by go-bindata.\n"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if _, err = fmt.Fprint(bfd, "// sources:\n"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
wd, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, asset := range toc {
|
||||||
|
relative, _ := filepath.Rel(wd, asset.Path)
|
||||||
|
if _, err = fmt.Fprintf(bfd, "// %s\n", filepath.ToSlash(relative)); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, err = fmt.Fprint(bfd, "// DO NOT EDIT!\n\n"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Write build tags, if applicable.
|
// Write build tags, if applicable.
|
||||||
if len(c.Tags) > 0 {
|
if len(c.Tags) > 0 {
|
||||||
_, err = fmt.Fprintf(fd, "// +build %s\n\n", c.Tags)
|
if _, err = fmt.Fprintf(bfd, "// +build %s\n\n", c.Tags); err != nil {
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write package declaration.
|
// Write package declaration.
|
||||||
_, err = fmt.Fprintf(fd, "package %s\n\n", c.Package)
|
_, err = fmt.Fprintf(bfd, "package %s\n\n", c.Package)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write assets.
|
// Write assets.
|
||||||
if c.Debug {
|
if c.Debug || c.Dev {
|
||||||
err = writeDebug(fd, toc)
|
err = writeDebug(bfd, c, toc)
|
||||||
} else {
|
} else {
|
||||||
err = writeRelease(fd, c, toc)
|
err = writeRelease(bfd, c, toc)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -65,44 +97,108 @@ func Translate(c *Config) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write table of contents
|
// Write table of contents
|
||||||
return writeTOC(fd, toc)
|
if err := writeTOC(bfd, toc); err != nil {
|
||||||
}
|
return err
|
||||||
|
}
|
||||||
// fillTOC recursively finds all the file paths in the given directory tree.
|
// Write hierarchical tree of assets
|
||||||
// They are added to the given map as keys. Values will be safe function names
|
if err := writeTOCTree(bfd, toc); err != nil {
|
||||||
// for each file, which will be used when generating the output code.
|
return err
|
||||||
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)
|
// Write restore procedure
|
||||||
|
return writeRestore(bfd)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Implement sort.Interface for []os.FileInfo based on Name()
|
||||||
|
type ByName []os.FileInfo
|
||||||
|
|
||||||
|
func (v ByName) Len() int { return len(v) }
|
||||||
|
func (v ByName) Swap(i, j int) { v[i], v[j] = v[j], v[i] }
|
||||||
|
func (v ByName) Less(i, j int) bool { return v[i].Name() < v[j].Name() }
|
||||||
|
|
||||||
|
// 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, ignore []*regexp.Regexp, knownFuncs map[string]int, visitedPaths map[string]bool) error {
|
||||||
|
dirpath := dir
|
||||||
|
if len(prefix) > 0 {
|
||||||
|
dirpath, _ = filepath.Abs(dirpath)
|
||||||
|
prefix, _ = filepath.Abs(prefix)
|
||||||
|
prefix = filepath.ToSlash(prefix)
|
||||||
|
}
|
||||||
|
|
||||||
|
fi, err := os.Stat(dirpath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var list []os.FileInfo
|
||||||
|
|
||||||
|
if !fi.IsDir() {
|
||||||
|
dirpath = filepath.Dir(dirpath)
|
||||||
|
list = []os.FileInfo{fi}
|
||||||
|
} else {
|
||||||
|
visitedPaths[dirpath] = true
|
||||||
|
fd, err := os.Open(dirpath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer fd.Close()
|
defer fd.Close()
|
||||||
|
|
||||||
list, err := fd.Readdir(0)
|
list, err = fd.Readdir(0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sort to make output stable between invocations
|
||||||
|
sort.Sort(ByName(list))
|
||||||
|
}
|
||||||
|
|
||||||
for _, file := range list {
|
for _, file := range list {
|
||||||
var asset Asset
|
var asset Asset
|
||||||
asset.Path = filepath.Join(dir, file.Name())
|
asset.Path = filepath.Join(dirpath, file.Name())
|
||||||
asset.Name = asset.Path
|
asset.Name = filepath.ToSlash(asset.Path)
|
||||||
|
|
||||||
|
ignoring := false
|
||||||
|
for _, re := range ignore {
|
||||||
|
if re.MatchString(asset.Path) {
|
||||||
|
ignoring = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ignoring {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if file.IsDir() {
|
if file.IsDir() {
|
||||||
if recursive {
|
if recursive {
|
||||||
findFiles(asset.Path, prefix, recursive, toc)
|
recursivePath := filepath.Join(dir, file.Name())
|
||||||
|
visitedPaths[asset.Path] = true
|
||||||
|
findFiles(recursivePath, prefix, recursive, toc, ignore, knownFuncs, visitedPaths)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
} else if file.Mode()&os.ModeSymlink == os.ModeSymlink {
|
||||||
|
var linkPath string
|
||||||
|
if linkPath, err = os.Readlink(asset.Path); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if !filepath.IsAbs(linkPath) {
|
||||||
|
if linkPath, err = filepath.Abs(dirpath + "/" + linkPath); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if _, ok := visitedPaths[linkPath]; !ok {
|
||||||
|
visitedPaths[linkPath] = true
|
||||||
|
findFiles(asset.Path, prefix, recursive, toc, ignore, knownFuncs, visitedPaths)
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if strings.HasPrefix(asset.Name, prefix) {
|
if strings.HasPrefix(asset.Name, prefix) {
|
||||||
asset.Name = asset.Name[len(prefix):]
|
asset.Name = asset.Name[len(prefix):]
|
||||||
|
} else {
|
||||||
|
asset.Name = filepath.Join(dir, file.Name())
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we have a leading slash, get rid of it.
|
// If we have a leading slash, get rid of it.
|
||||||
|
@ -115,7 +211,7 @@ func findFiles(dir, prefix string, recursive bool, toc *[]Asset) error {
|
||||||
return fmt.Errorf("Invalid file: %v", asset.Path)
|
return fmt.Errorf("Invalid file: %v", asset.Path)
|
||||||
}
|
}
|
||||||
|
|
||||||
asset.Func = safeFunctionName(asset.Name)
|
asset.Func = safeFunctionName(asset.Name, knownFuncs)
|
||||||
asset.Path, _ = filepath.Abs(asset.Path)
|
asset.Path, _ = filepath.Abs(asset.Path)
|
||||||
*toc = append(*toc, asset)
|
*toc = append(*toc, asset)
|
||||||
}
|
}
|
||||||
|
@ -126,25 +222,40 @@ func findFiles(dir, prefix string, recursive bool, toc *[]Asset) error {
|
||||||
var regFuncName = regexp.MustCompile(`[^a-zA-Z0-9_]`)
|
var regFuncName = regexp.MustCompile(`[^a-zA-Z0-9_]`)
|
||||||
|
|
||||||
// safeFunctionName converts the given name into a name
|
// safeFunctionName converts the given name into a name
|
||||||
// which qualifies as a valid function identifier.
|
// which qualifies as a valid function identifier. It
|
||||||
func safeFunctionName(name string) string {
|
// also compares against a known list of functions to
|
||||||
|
// prevent conflict based on name translation.
|
||||||
|
func safeFunctionName(name string, knownFuncs map[string]int) string {
|
||||||
|
var inBytes, outBytes []byte
|
||||||
|
var toUpper bool
|
||||||
|
|
||||||
name = strings.ToLower(name)
|
name = strings.ToLower(name)
|
||||||
name = regFuncName.ReplaceAllString(name, "_")
|
inBytes = []byte(name)
|
||||||
|
|
||||||
// Get rid of "__" instances for niceness.
|
for i := 0; i < len(inBytes); i++ {
|
||||||
for strings.Index(name, "__") > -1 {
|
if regFuncName.Match([]byte{inBytes[i]}) {
|
||||||
name = strings.Replace(name, "__", "_", -1)
|
toUpper = true
|
||||||
|
} else if toUpper {
|
||||||
|
outBytes = append(outBytes, []byte(strings.ToUpper(string(inBytes[i])))...)
|
||||||
|
toUpper = false
|
||||||
|
} else {
|
||||||
|
outBytes = append(outBytes, inBytes[i])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Leading underscores are silly (unless they prefix a digit (see below)).
|
name = string(outBytes)
|
||||||
for len(name) > 1 && name[0] == '_' {
|
|
||||||
name = name[1:]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Identifier can't start with a digit.
|
// Identifier can't start with a digit.
|
||||||
if unicode.IsDigit(rune(name[0])) {
|
if unicode.IsDigit(rune(name[0])) {
|
||||||
name = "_" + name
|
name = "_" + name
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if num, ok := knownFuncs[name]; ok {
|
||||||
|
knownFuncs[name] = num + 1
|
||||||
|
name = fmt.Sprintf("%s%d", name, num)
|
||||||
|
} else {
|
||||||
|
knownFuncs[name] = 2
|
||||||
|
}
|
||||||
|
|
||||||
return name
|
return name
|
||||||
}
|
}
|
||||||
|
|
90
convert_test.go
Normal file
90
convert_test.go
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
package bindata
|
||||||
|
|
||||||
|
import (
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSafeFunctionName(t *testing.T) {
|
||||||
|
var knownFuncs = make(map[string]int)
|
||||||
|
name1 := safeFunctionName("foo/bar", knownFuncs)
|
||||||
|
name2 := safeFunctionName("foo_bar", knownFuncs)
|
||||||
|
if name1 == name2 {
|
||||||
|
t.Errorf("name collision")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFindFiles(t *testing.T) {
|
||||||
|
var toc []Asset
|
||||||
|
var knownFuncs = make(map[string]int)
|
||||||
|
var visitedPaths = make(map[string]bool)
|
||||||
|
err := findFiles("testdata/dupname", "testdata/dupname", true, &toc, []*regexp.Regexp{}, knownFuncs, visitedPaths)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("expected to be no error: %+v", err)
|
||||||
|
}
|
||||||
|
if toc[0].Func == toc[1].Func {
|
||||||
|
t.Errorf("name collision")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFindFilesWithSymlinks(t *testing.T) {
|
||||||
|
var tocSrc []Asset
|
||||||
|
var tocTarget []Asset
|
||||||
|
|
||||||
|
var knownFuncs = make(map[string]int)
|
||||||
|
var visitedPaths = make(map[string]bool)
|
||||||
|
err := findFiles("testdata/symlinkSrc", "testdata/symlinkSrc", true, &tocSrc, []*regexp.Regexp{}, knownFuncs, visitedPaths)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("expected to be no error: %+v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
knownFuncs = make(map[string]int)
|
||||||
|
visitedPaths = make(map[string]bool)
|
||||||
|
err = findFiles("testdata/symlinkParent", "testdata/symlinkParent", true, &tocTarget, []*regexp.Regexp{}, knownFuncs, visitedPaths)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("expected to be no error: %+v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(tocSrc) != len(tocTarget) {
|
||||||
|
t.Errorf("Symlink source and target should have the same number of assets. Expected %d got %d", len(tocTarget), len(tocSrc))
|
||||||
|
} else {
|
||||||
|
for i, _ := range tocSrc {
|
||||||
|
targetFunc := strings.TrimPrefix(tocTarget[i].Func, "symlinktarget")
|
||||||
|
targetFunc = strings.ToLower(targetFunc[:1]) + targetFunc[1:]
|
||||||
|
if tocSrc[i].Func != targetFunc {
|
||||||
|
t.Errorf("Symlink source and target produced different function lists. Expected %s to be %s", targetFunc, tocSrc[i].Func)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFindFilesWithRecursiveSymlinks(t *testing.T) {
|
||||||
|
var toc []Asset
|
||||||
|
|
||||||
|
var knownFuncs = make(map[string]int)
|
||||||
|
var visitedPaths = make(map[string]bool)
|
||||||
|
err := findFiles("testdata/symlinkRecursiveParent", "testdata/symlinkRecursiveParent", true, &toc, []*regexp.Regexp{}, knownFuncs, visitedPaths)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("expected to be no error: %+v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(toc) != 1 {
|
||||||
|
t.Errorf("Only one asset should have been found. Got %d: %v", len(toc), toc)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFindFilesWithSymlinkedFile(t *testing.T) {
|
||||||
|
var toc []Asset
|
||||||
|
|
||||||
|
var knownFuncs = make(map[string]int)
|
||||||
|
var visitedPaths = make(map[string]bool)
|
||||||
|
err := findFiles("testdata/symlinkFile", "testdata/symlinkFile", true, &toc, []*regexp.Regexp{}, knownFuncs, visitedPaths)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("expected to be no error: %+v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(toc) != 1 {
|
||||||
|
t.Errorf("Only one asset should have been found. Got %d: %v", len(toc), toc)
|
||||||
|
}
|
||||||
|
}
|
68
debug.go
68
debug.go
|
@ -10,14 +10,14 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// writeDebug writes the debug code file.
|
// writeDebug writes the debug code file.
|
||||||
func writeDebug(w io.Writer, toc []Asset) error {
|
func writeDebug(w io.Writer, c *Config, toc []Asset) error {
|
||||||
err := writeDebugHeader(w)
|
err := writeDebugHeader(w)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range toc {
|
for i := range toc {
|
||||||
err = writeDebugAsset(w, &toc[i])
|
err = writeDebugAsset(w, c, &toc[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -30,29 +30,25 @@ func writeDebug(w io.Writer, toc []Asset) error {
|
||||||
// This targets debug builds.
|
// This targets debug builds.
|
||||||
func writeDebugHeader(w io.Writer) error {
|
func writeDebugHeader(w io.Writer) error {
|
||||||
_, err := fmt.Fprintf(w, `import (
|
_, err := fmt.Fprintf(w, `import (
|
||||||
"bytes"
|
"fmt"
|
||||||
"io"
|
"io/ioutil"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// bindata_read reads the given file from disk.
|
// bindataRead reads the given file from disk. It returns an error on failure.
|
||||||
// It panics if anything went wrong.
|
func bindataRead(path, name string) ([]byte, error) {
|
||||||
func bindata_read(path, name string) []byte {
|
buf, err := ioutil.ReadFile(path)
|
||||||
fd, err := os.Open(path)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Read %%s: %%v", name, err)
|
err = fmt.Errorf("Error reading asset %%s at %%s: %%v", name, path, err)
|
||||||
}
|
}
|
||||||
|
return buf, err
|
||||||
|
}
|
||||||
|
|
||||||
defer fd.Close()
|
type asset struct {
|
||||||
|
bytes []byte
|
||||||
var buf bytes.Buffer
|
info os.FileInfo
|
||||||
_, err = io.Copy(&buf, fd)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("Read %%s: %%v", name, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return buf.Bytes()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
`)
|
`)
|
||||||
|
@ -62,16 +58,30 @@ func bindata_read(path, name string) []byte {
|
||||||
// writeDebugAsset write a debug entry for the given asset.
|
// writeDebugAsset write a debug entry for the given asset.
|
||||||
// A debug entry is simply a function which reads the asset from
|
// A debug entry is simply a function which reads the asset from
|
||||||
// the original file (e.g.: from disk).
|
// the original file (e.g.: from disk).
|
||||||
func writeDebugAsset(w io.Writer, asset *Asset) error {
|
func writeDebugAsset(w io.Writer, c *Config, asset *Asset) error {
|
||||||
_, err := fmt.Fprintf(w, `
|
pathExpr := fmt.Sprintf("%q", asset.Path)
|
||||||
// %s reads file data from disk.
|
if c.Dev {
|
||||||
// It panics if something went wrong in the process.
|
pathExpr = fmt.Sprintf("filepath.Join(rootDir, %q)", asset.Name)
|
||||||
func %s() []byte {
|
}
|
||||||
return bindata_read(
|
|
||||||
%q,
|
_, err := fmt.Fprintf(w, `// %s reads file data from disk. It returns an error on failure.
|
||||||
%q,
|
func %s() (*asset, error) {
|
||||||
)
|
path := %s
|
||||||
|
name := %q
|
||||||
|
bytes, err := bindataRead(path, name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
fi, err := os.Stat(path)
|
||||||
|
if err != nil {
|
||||||
|
err = fmt.Errorf("Error reading asset info %%s at %%s: %%v", name, path, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
a := &asset{bytes: bytes, info: fi}
|
||||||
|
return a, err
|
||||||
}
|
}
|
||||||
`, asset.Func, asset.Func, asset.Path, asset.Name)
|
|
||||||
|
`, asset.Func, asset.Func, pathExpr, asset.Name)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
22
go-bindata/AppendSliceValue.go
Normal file
22
go-bindata/AppendSliceValue.go
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
|
// borrowed from https://github.com/hashicorp/serf/blob/master/command/agent/flag_slice_value.go
|
||||||
|
|
||||||
|
// AppendSliceValue implements the flag.Value interface and allows multiple
|
||||||
|
// calls to the same variable to append a list.
|
||||||
|
type AppendSliceValue []string
|
||||||
|
|
||||||
|
func (s *AppendSliceValue) String() string {
|
||||||
|
return strings.Join(*s, ",")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *AppendSliceValue) Set(value string) error {
|
||||||
|
if *s == nil {
|
||||||
|
*s = make([]string, 0, 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
*s = append(*s, value)
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -7,9 +7,12 @@ package main
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/jteeuwen/go-bindata"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"git.kirsle.net/go/bindata"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -33,36 +36,72 @@ func parseArgs() *bindata.Config {
|
||||||
c := bindata.NewConfig()
|
c := bindata.NewConfig()
|
||||||
|
|
||||||
flag.Usage = func() {
|
flag.Usage = func() {
|
||||||
fmt.Printf("Usage: %s [options] <input dir> [<output file>]\n\n", os.Args[0])
|
fmt.Printf("Usage: %s [options] <input directories>\n\n", os.Args[0])
|
||||||
flag.PrintDefaults()
|
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.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.BoolVar(&c.Dev, "dev", c.Dev, "Similar to debug, but does not emit absolute paths. Expects a rootDir variable to already exist in the generated code's package.")
|
||||||
|
flag.StringVar(&c.Tags, "tags", c.Tags, "Optional set of build tags to include.")
|
||||||
flag.StringVar(&c.Prefix, "prefix", c.Prefix, "Optional path prefix to strip off asset names.")
|
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.StringVar(&c.Package, "pkg", c.Package, "Package name to use in the generated code.")
|
||||||
flag.BoolVar(&c.Recursive, "r", c.Recursive, "Recursive processing of the target directory and all its sub-directories.")
|
|
||||||
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.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.BoolVar(&c.NoCompress, "nocompress", c.NoCompress, "Assets will *not* be GZIP compressed when this flag is specified.")
|
||||||
|
flag.BoolVar(&c.NoMetadata, "nometadata", c.NoMetadata, "Assets will not preserve size, mode, and modtime info.")
|
||||||
|
flag.UintVar(&c.Mode, "mode", c.Mode, "Optional file mode override for all files.")
|
||||||
|
flag.Int64Var(&c.ModTime, "modtime", c.ModTime, "Optional modification unix timestamp override for all files.")
|
||||||
|
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.BoolVar(&version, "version", false, "Displays version information.")
|
||||||
|
|
||||||
|
ignore := make([]string, 0)
|
||||||
|
flag.Var((*AppendSliceValue)(&ignore), "ignore", "Regex pattern to ignore")
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
patterns := make([]*regexp.Regexp, 0)
|
||||||
|
for _, pattern := range ignore {
|
||||||
|
patterns = append(patterns, regexp.MustCompile(pattern))
|
||||||
|
}
|
||||||
|
c.Ignore = patterns
|
||||||
|
|
||||||
if version {
|
if version {
|
||||||
fmt.Printf("%s\n", Version())
|
fmt.Printf("%s\n", Version())
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure we have in/output paths.
|
// Make sure we have input paths.
|
||||||
if flag.NArg() == 0 {
|
if flag.NArg() == 0 {
|
||||||
fmt.Fprintf(os.Stderr, "Missing input path.\n")
|
fmt.Fprintf(os.Stderr, "Missing <input dir>\n\n")
|
||||||
|
flag.Usage()
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
c.Input = filepath.Clean(flag.Arg(0))
|
// Create input configurations.
|
||||||
|
c.Input = make([]bindata.InputConfig, flag.NArg())
|
||||||
if flag.NArg() > 1 {
|
for i := range c.Input {
|
||||||
c.Output = filepath.Clean(flag.Arg(1))
|
c.Input[i] = parseInput(flag.Arg(i))
|
||||||
}
|
}
|
||||||
|
|
||||||
return c
|
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,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
225
release.go
225
release.go
|
@ -5,10 +5,13 @@
|
||||||
package bindata
|
package bindata
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"unicode/utf8"
|
||||||
)
|
)
|
||||||
|
|
||||||
// writeRelease writes the release code file.
|
// writeRelease writes the release code file.
|
||||||
|
@ -31,19 +34,24 @@ func writeRelease(w io.Writer, c *Config, toc []Asset) error {
|
||||||
// writeReleaseHeader writes output file headers.
|
// writeReleaseHeader writes output file headers.
|
||||||
// This targets release builds.
|
// This targets release builds.
|
||||||
func writeReleaseHeader(w io.Writer, c *Config) error {
|
func writeReleaseHeader(w io.Writer, c *Config) error {
|
||||||
|
var err error
|
||||||
if c.NoCompress {
|
if c.NoCompress {
|
||||||
if c.NoMemCopy {
|
if c.NoMemCopy {
|
||||||
return header_uncompressed_nomemcopy(w)
|
err = header_uncompressed_nomemcopy(w)
|
||||||
} else {
|
} else {
|
||||||
return header_uncompressed_memcopy(w)
|
err = header_uncompressed_memcopy(w)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if c.NoMemCopy {
|
if c.NoMemCopy {
|
||||||
return header_compressed_nomemcopy(w)
|
err = header_compressed_nomemcopy(w)
|
||||||
} else {
|
} else {
|
||||||
return header_compressed_memcopy(w)
|
err = header_compressed_memcopy(w)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return header_release_common(w)
|
||||||
}
|
}
|
||||||
|
|
||||||
// writeReleaseAsset write a release entry for the given asset.
|
// writeReleaseAsset write a release entry for the given asset.
|
||||||
|
@ -59,54 +67,67 @@ func writeReleaseAsset(w io.Writer, c *Config, asset *Asset) error {
|
||||||
|
|
||||||
if c.NoCompress {
|
if c.NoCompress {
|
||||||
if c.NoMemCopy {
|
if c.NoMemCopy {
|
||||||
return uncompressed_nomemcopy(w, asset, fd)
|
err = uncompressed_nomemcopy(w, asset, fd)
|
||||||
} else {
|
} else {
|
||||||
return uncompressed_memcopy(w, asset, fd)
|
err = uncompressed_memcopy(w, asset, fd)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if c.NoMemCopy {
|
if c.NoMemCopy {
|
||||||
return compressed_nomemcopy(w, asset, fd)
|
err = compressed_nomemcopy(w, asset, fd)
|
||||||
} else {
|
} else {
|
||||||
return compressed_memcopy(w, asset, fd)
|
err = compressed_memcopy(w, asset, fd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return asset_release_common(w, c, asset)
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
// sanitize prepares a valid UTF-8 string as a raw string constant.
|
||||||
|
// Based on https://code.google.com/p/go/source/browse/godoc/static/makestatic.go?repo=tools
|
||||||
|
func sanitize(b []byte) []byte {
|
||||||
|
// Replace ` with `+"`"+`
|
||||||
|
b = bytes.Replace(b, []byte("`"), []byte("`+\"`\"+`"), -1)
|
||||||
|
|
||||||
|
// Replace BOM with `+"\xEF\xBB\xBF"+`
|
||||||
|
// (A BOM is valid UTF-8 but not permitted in Go source files.
|
||||||
|
// I wouldn't bother handling this, but for some insane reason
|
||||||
|
// jquery.js has a BOM somewhere in the middle.)
|
||||||
|
return bytes.Replace(b, []byte("\xEF\xBB\xBF"), []byte("`+\"\\xEF\\xBB\\xBF\"+`"), -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func header_compressed_nomemcopy(w io.Writer) error {
|
func header_compressed_nomemcopy(w io.Writer) error {
|
||||||
_, err := fmt.Fprintf(w, `import (
|
_, err := fmt.Fprintf(w, `import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"io/ioutil"
|
||||||
"reflect"
|
"os"
|
||||||
"unsafe"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func bindata_read(data, name string) []byte {
|
func bindataRead(data, name string) ([]byte, error) {
|
||||||
var empty [0]byte
|
gz, err := gzip.NewReader(strings.NewReader(data))
|
||||||
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 {
|
if err != nil {
|
||||||
log.Fatalf("Read %%q: %%v", name, err)
|
return nil, fmt.Errorf("Read %%q: %%v", name, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
_, err = io.Copy(&buf, gz)
|
_, err = io.Copy(&buf, gz)
|
||||||
gz.Close()
|
clErr := gz.Close()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Read %%q: %%v", name, err)
|
return nil, fmt.Errorf("Read %%q: %%v", name, err)
|
||||||
|
}
|
||||||
|
if clErr != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return buf.Bytes()
|
return buf.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
`)
|
`)
|
||||||
|
@ -117,25 +138,33 @@ func header_compressed_memcopy(w io.Writer) error {
|
||||||
_, err := fmt.Fprintf(w, `import (
|
_, err := fmt.Fprintf(w, `import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func bindata_read(data []byte, name string) []byte {
|
func bindataRead(data []byte, name string) ([]byte, error) {
|
||||||
gz, err := gzip.NewReader(bytes.NewBuffer(data))
|
gz, err := gzip.NewReader(bytes.NewBuffer(data))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Read %%q: %%v", name, err)
|
return nil, fmt.Errorf("Read %%q: %%v", name, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
_, err = io.Copy(&buf, gz)
|
_, err = io.Copy(&buf, gz)
|
||||||
gz.Close()
|
clErr := gz.Close()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Read %%q: %%v", name, err)
|
return nil, fmt.Errorf("Read %%q: %%v", name, err)
|
||||||
|
}
|
||||||
|
if clErr != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return buf.Bytes()
|
return buf.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
`)
|
`)
|
||||||
|
@ -144,11 +173,17 @@ func bindata_read(data []byte, name string) []byte {
|
||||||
|
|
||||||
func header_uncompressed_nomemcopy(w io.Writer) error {
|
func header_uncompressed_nomemcopy(w io.Writer) error {
|
||||||
_, err := fmt.Fprintf(w, `import (
|
_, err := fmt.Fprintf(w, `import (
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
func bindata_read(data, name string) []byte {
|
func bindataRead(data, name string) ([]byte, error) {
|
||||||
var empty [0]byte
|
var empty [0]byte
|
||||||
sx := (*reflect.StringHeader)(unsafe.Pointer(&data))
|
sx := (*reflect.StringHeader)(unsafe.Pointer(&data))
|
||||||
b := empty[:]
|
b := empty[:]
|
||||||
|
@ -156,7 +191,7 @@ func bindata_read(data, name string) []byte {
|
||||||
bx.Data = sx.Data
|
bx.Data = sx.Data
|
||||||
bx.Len = len(data)
|
bx.Len = len(data)
|
||||||
bx.Cap = bx.Len
|
bx.Cap = bx.Len
|
||||||
return b
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
`)
|
`)
|
||||||
|
@ -164,10 +199,54 @@ func bindata_read(data, name string) []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func header_uncompressed_memcopy(w io.Writer) error {
|
func header_uncompressed_memcopy(w io.Writer) error {
|
||||||
// nop -- We require no imports or helper functions.
|
_, err := fmt.Fprintf(w, `import (
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
`)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func header_release_common(w io.Writer) error {
|
||||||
|
_, err := fmt.Fprintf(w, `type asset struct {
|
||||||
|
bytes []byte
|
||||||
|
info os.FileInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
type bindataFileInfo struct {
|
||||||
|
name string
|
||||||
|
size int64
|
||||||
|
mode os.FileMode
|
||||||
|
modTime time.Time
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fi bindataFileInfo) Name() string {
|
||||||
|
return fi.name
|
||||||
|
}
|
||||||
|
func (fi bindataFileInfo) Size() int64 {
|
||||||
|
return fi.size
|
||||||
|
}
|
||||||
|
func (fi bindataFileInfo) Mode() os.FileMode {
|
||||||
|
return fi.mode
|
||||||
|
}
|
||||||
|
func (fi bindataFileInfo) ModTime() time.Time {
|
||||||
|
return fi.modTime
|
||||||
|
}
|
||||||
|
func (fi bindataFileInfo) IsDir() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
func (fi bindataFileInfo) Sys() interface{} {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
`)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func compressed_nomemcopy(w io.Writer, asset *Asset, r io.Reader) error {
|
func compressed_nomemcopy(w io.Writer, asset *Asset, r io.Reader) error {
|
||||||
_, err := fmt.Fprintf(w, `var _%s = "`, asset.Func)
|
_, err := fmt.Fprintf(w, `var _%s = "`, asset.Func)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -184,8 +263,8 @@ func compressed_nomemcopy(w io.Writer, asset *Asset, r io.Reader) error {
|
||||||
|
|
||||||
_, err = fmt.Fprintf(w, `"
|
_, err = fmt.Fprintf(w, `"
|
||||||
|
|
||||||
func %s() []byte {
|
func %sBytes() ([]byte, error) {
|
||||||
return bindata_read(
|
return bindataRead(
|
||||||
_%s,
|
_%s,
|
||||||
%q,
|
%q,
|
||||||
)
|
)
|
||||||
|
@ -196,14 +275,12 @@ func %s() []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func compressed_memcopy(w io.Writer, asset *Asset, r io.Reader) error {
|
func compressed_memcopy(w io.Writer, asset *Asset, r io.Reader) error {
|
||||||
_, err := fmt.Fprintf(w, `func %s() []byte {
|
_, err := fmt.Fprintf(w, `var _%s = []byte("`, asset.Func)
|
||||||
return bindata_read([]byte{`, asset.Func)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
gz := gzip.NewWriter(&ByteWriter{Writer: w})
|
gz := gzip.NewWriter(&StringWriter{Writer: w})
|
||||||
_, err = io.Copy(gz, r)
|
_, err = io.Copy(gz, r)
|
||||||
gz.Close()
|
gz.Close()
|
||||||
|
|
||||||
|
@ -211,13 +288,16 @@ func compressed_memcopy(w io.Writer, asset *Asset, r io.Reader) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = fmt.Fprintf(w, `
|
_, err = fmt.Fprintf(w, `")
|
||||||
},
|
|
||||||
|
func %sBytes() ([]byte, error) {
|
||||||
|
return bindataRead(
|
||||||
|
_%s,
|
||||||
%q,
|
%q,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
`, asset.Name)
|
`, asset.Func, asset.Func, asset.Name)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -234,8 +314,8 @@ func uncompressed_nomemcopy(w io.Writer, asset *Asset, r io.Reader) error {
|
||||||
|
|
||||||
_, err = fmt.Fprintf(w, `"
|
_, err = fmt.Fprintf(w, `"
|
||||||
|
|
||||||
func %s() []byte {
|
func %sBytes() ([]byte, error) {
|
||||||
return bindata_read(
|
return bindataRead(
|
||||||
_%s,
|
_%s,
|
||||||
%q,
|
%q,
|
||||||
)
|
)
|
||||||
|
@ -246,21 +326,62 @@ func %s() []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
func uncompressed_memcopy(w io.Writer, asset *Asset, r io.Reader) error {
|
func uncompressed_memcopy(w io.Writer, asset *Asset, r io.Reader) error {
|
||||||
_, err := fmt.Fprintf(w, `func %s() []byte {
|
_, err := fmt.Fprintf(w, `var _%s = []byte(`, asset.Func)
|
||||||
return []byte{`, asset.Func)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = io.Copy(&ByteWriter{Writer: w}, r)
|
b, err := ioutil.ReadAll(r)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if utf8.Valid(b) && !bytes.Contains(b, []byte{0}) {
|
||||||
|
fmt.Fprintf(w, "`%s`", sanitize(b))
|
||||||
|
} else {
|
||||||
|
fmt.Fprintf(w, "%+q", b)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = fmt.Fprintf(w, `)
|
||||||
|
|
||||||
|
func %sBytes() ([]byte, error) {
|
||||||
|
return _%s, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
`, asset.Func, asset.Func)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func asset_release_common(w io.Writer, c *Config, asset *Asset) error {
|
||||||
|
fi, err := os.Stat(asset.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = fmt.Fprintf(w, `
|
mode := uint(fi.Mode())
|
||||||
|
modTime := fi.ModTime().Unix()
|
||||||
|
size := fi.Size()
|
||||||
|
if c.NoMetadata {
|
||||||
|
mode = 0
|
||||||
|
modTime = 0
|
||||||
|
size = 0
|
||||||
}
|
}
|
||||||
|
if c.Mode > 0 {
|
||||||
|
mode = uint(os.ModePerm) & c.Mode
|
||||||
|
}
|
||||||
|
if c.ModTime > 0 {
|
||||||
|
modTime = c.ModTime
|
||||||
|
}
|
||||||
|
_, err = fmt.Fprintf(w, `func %s() (*asset, error) {
|
||||||
|
bytes, err := %sBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
info := bindataFileInfo{name: %q, size: %d, mode: os.FileMode(%d), modTime: time.Unix(%d, 0)}
|
||||||
|
a := &asset{bytes: bytes, info: info}
|
||||||
|
return a, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
`)
|
`, asset.Func, asset.Func, asset.Name, size, mode, modTime)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
63
restore.go
Normal file
63
restore.go
Normal file
|
@ -0,0 +1,63 @@
|
||||||
|
// 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"
|
||||||
|
)
|
||||||
|
|
||||||
|
func writeRestore(w io.Writer) error {
|
||||||
|
_, err := fmt.Fprintf(w, `
|
||||||
|
// RestoreAsset restores an asset under the given directory
|
||||||
|
func RestoreAsset(dir, name string) error {
|
||||||
|
data, err := Asset(name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
info, err := AssetInfo(name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// RestoreAssets restores an asset under the given directory recursively
|
||||||
|
func RestoreAssets(dir, name string) error {
|
||||||
|
children, err := AssetDir(name)
|
||||||
|
// File
|
||||||
|
if err != nil {
|
||||||
|
return RestoreAsset(dir, name)
|
||||||
|
}
|
||||||
|
// Dir
|
||||||
|
for _, child := range children {
|
||||||
|
err = RestoreAssets(dir, filepath.Join(name, child))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func _filePath(dir, name string) string {
|
||||||
|
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||||
|
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
`)
|
||||||
|
return err
|
||||||
|
}
|
|
@ -5,10 +5,11 @@
|
||||||
package bindata
|
package bindata
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const lowerHex = "0123456789abcdef"
|
||||||
|
|
||||||
type StringWriter struct {
|
type StringWriter struct {
|
||||||
io.Writer
|
io.Writer
|
||||||
c int
|
c int
|
||||||
|
@ -19,8 +20,13 @@ func (w *StringWriter) Write(p []byte) (n int, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for n = range p {
|
buf := []byte(`\x00`)
|
||||||
fmt.Fprintf(w.Writer, "\\x%02x", p[n])
|
var b byte
|
||||||
|
|
||||||
|
for n, b = range p {
|
||||||
|
buf[2] = lowerHex[b/16]
|
||||||
|
buf[3] = lowerHex[b%16]
|
||||||
|
w.Writer.Write(buf)
|
||||||
w.c++
|
w.c++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
37
testdata/Makefile
vendored
Normal file
37
testdata/Makefile
vendored
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
FILES:=$(wildcard out/*.go)
|
||||||
|
|
||||||
|
.PHONY: check
|
||||||
|
check: errcheck vet golint $(FILES:.go=.checked)
|
||||||
|
|
||||||
|
out/%.checked: out/%.go
|
||||||
|
errcheck $<
|
||||||
|
go tool vet --all $<
|
||||||
|
go tool vet --shadow $<
|
||||||
|
golint $<
|
||||||
|
|
||||||
|
$(GOPATH)/bin/go-bindata: $(wildcard ../*.go) $(wildcard ../**/*.go)
|
||||||
|
go install ../...
|
||||||
|
|
||||||
|
out/compress-memcopy.go: $(wildcard in/**/*) $(GOPATH)/bin/go-bindata
|
||||||
|
$(GOPATH)/bin/go-bindata -o $@ in/...
|
||||||
|
|
||||||
|
out/compress-nomemcopy.go: $(wildcard in/**/*) $(GOPATH)/bin/go-bindata
|
||||||
|
$(GOPATH)/bin/go-bindata -nomemcopy -o $@ in/...
|
||||||
|
|
||||||
|
out/debug.go: $(wildcard in/**/*) $(GOPATH)/bin/go-bindata
|
||||||
|
$(GOPATH)/bin/go-bindata -debug -o $@ in/...
|
||||||
|
|
||||||
|
out/nocompress-memcopy.go: $(wildcard in/**/*) $(GOPATH)/bin/go-bindata
|
||||||
|
$(GOPATH)/bin/go-bindata -nocompress -o $@ in/...
|
||||||
|
|
||||||
|
out/nocompress-nomemcopy.go: $(wildcard in/**/*) $(GOPATH)/bin/go-bindata
|
||||||
|
$(GOPATH)/bin/go-bindata -nocompress -nomemcopy -o $@ in/...
|
||||||
|
|
||||||
|
errcheck:
|
||||||
|
go get github.com/kisielk/errcheck
|
||||||
|
|
||||||
|
vet:
|
||||||
|
go get golang.org/x/tools/cmd/vet
|
||||||
|
|
||||||
|
golint:
|
||||||
|
go get github.com/golang/lint/golint
|
1
testdata/dupname/foo/bar
vendored
Normal file
1
testdata/dupname/foo/bar
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
// sample file
|
1
testdata/dupname/foo_bar
vendored
Normal file
1
testdata/dupname/foo_bar
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
// sample file
|
322
testdata/out/compress-memcopy.go
vendored
322
testdata/out/compress-memcopy.go
vendored
|
@ -1,86 +1,312 @@
|
||||||
|
// Code generated by go-bindata.
|
||||||
|
// sources:
|
||||||
|
// in/a/test.asset
|
||||||
|
// in/b/test.asset
|
||||||
|
// in/c/test.asset
|
||||||
|
// in/test.asset
|
||||||
|
// DO NOT EDIT!
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func bindata_read(data []byte, name string) []byte {
|
func bindataRead(data []byte, name string) ([]byte, error) {
|
||||||
gz, err := gzip.NewReader(bytes.NewBuffer(data))
|
gz, err := gzip.NewReader(bytes.NewBuffer(data))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Read %q: %v", name, err)
|
return nil, fmt.Errorf("Read %q: %v", name, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
_, err = io.Copy(&buf, gz)
|
_, err = io.Copy(&buf, gz)
|
||||||
gz.Close()
|
clErr := gz.Close()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Read %q: %v", name, err)
|
return nil, fmt.Errorf("Read %q: %v", name, err)
|
||||||
|
}
|
||||||
|
if clErr != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return buf.Bytes()
|
return buf.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func in_b_test_asset() []byte {
|
type asset struct {
|
||||||
return bindata_read([]byte{
|
bytes []byte
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x00, 0xff, 0xd2, 0xd7,
|
info os.FileInfo
|
||||||
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 {
|
type bindataFileInfo struct {
|
||||||
return bindata_read([]byte{
|
name string
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x00, 0xff, 0xd2, 0xd7,
|
size int64
|
||||||
0x57, 0x28, 0x4e, 0xcc, 0x2d, 0xc8, 0x49, 0x55, 0x48, 0xcb, 0xcc, 0x49,
|
mode os.FileMode
|
||||||
0xe5, 0x02, 0x04, 0x00, 0x00, 0xff, 0xff, 0x8a, 0x82, 0x8c, 0x85, 0x0f,
|
modTime time.Time
|
||||||
0x00, 0x00, 0x00,
|
|
||||||
},
|
|
||||||
"in/test.asset",
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func in_a_test_asset() []byte {
|
func (fi bindataFileInfo) Name() string {
|
||||||
return bindata_read([]byte{
|
return fi.name
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x00, 0xff, 0xd2, 0xd7,
|
}
|
||||||
0x57, 0x28, 0x4e, 0xcc, 0x2d, 0xc8, 0x49, 0x55, 0x48, 0xcb, 0xcc, 0x49,
|
func (fi bindataFileInfo) Size() int64 {
|
||||||
0xe5, 0x02, 0x04, 0x00, 0x00, 0xff, 0xff, 0x8a, 0x82, 0x8c, 0x85, 0x0f,
|
return fi.size
|
||||||
0x00, 0x00, 0x00,
|
}
|
||||||
},
|
func (fi bindataFileInfo) Mode() os.FileMode {
|
||||||
|
return fi.mode
|
||||||
|
}
|
||||||
|
func (fi bindataFileInfo) ModTime() time.Time {
|
||||||
|
return fi.modTime
|
||||||
|
}
|
||||||
|
func (fi bindataFileInfo) IsDir() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
func (fi bindataFileInfo) Sys() interface{} {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var _inATestAsset = []byte("\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 inATestAssetBytes() ([]byte, error) {
|
||||||
|
return bindataRead(
|
||||||
|
_inATestAsset,
|
||||||
"in/a/test.asset",
|
"in/a/test.asset",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
func in_c_test_asset() []byte {
|
func inATestAsset() (*asset, error) {
|
||||||
return bindata_read([]byte{
|
bytes, err := inATestAssetBytes()
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x00, 0xff, 0xd2, 0xd7,
|
if err != nil {
|
||||||
0x57, 0x28, 0x4e, 0xcc, 0x2d, 0xc8, 0x49, 0x55, 0x48, 0xcb, 0xcc, 0x49,
|
return nil, err
|
||||||
0xe5, 0x02, 0x04, 0x00, 0x00, 0xff, 0xff, 0x8a, 0x82, 0x8c, 0x85, 0x0f,
|
}
|
||||||
0x00, 0x00, 0x00,
|
|
||||||
},
|
info := bindataFileInfo{name: "in/a/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
|
||||||
|
a := &asset{bytes: bytes, info: info}
|
||||||
|
return a, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var _inBTestAsset = []byte("\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 inBTestAssetBytes() ([]byte, error) {
|
||||||
|
return bindataRead(
|
||||||
|
_inBTestAsset,
|
||||||
|
"in/b/test.asset",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func inBTestAsset() (*asset, error) {
|
||||||
|
bytes, err := inBTestAssetBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
info := bindataFileInfo{name: "in/b/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
|
||||||
|
a := &asset{bytes: bytes, info: info}
|
||||||
|
return a, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var _inCTestAsset = []byte("\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 inCTestAssetBytes() ([]byte, error) {
|
||||||
|
return bindataRead(
|
||||||
|
_inCTestAsset,
|
||||||
"in/c/test.asset",
|
"in/c/test.asset",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func inCTestAsset() (*asset, error) {
|
||||||
|
bytes, err := inCTestAssetBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
info := bindataFileInfo{name: "in/c/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
|
||||||
|
a := &asset{bytes: bytes, info: info}
|
||||||
|
return a, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var _inTestAsset = []byte("\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 inTestAssetBytes() ([]byte, error) {
|
||||||
|
return bindataRead(
|
||||||
|
_inTestAsset,
|
||||||
|
"in/test.asset",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func inTestAsset() (*asset, error) {
|
||||||
|
bytes, err := inTestAssetBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
info := bindataFileInfo{name: "in/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
|
||||||
|
a := &asset{bytes: bytes, info: info}
|
||||||
|
return a, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Asset loads and returns the asset for the given name.
|
// Asset loads and returns the asset for the given name.
|
||||||
// This returns nil of the asset could not be found.
|
// It returns an error if the asset could not be found or
|
||||||
func Asset(name string) []byte {
|
// could not be loaded.
|
||||||
if f, ok := _bindata[name]; ok {
|
func Asset(name string) ([]byte, error) {
|
||||||
return f()
|
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||||
|
if f, ok := _bindata[cannonicalName]; ok {
|
||||||
|
a, err := f()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
|
||||||
|
}
|
||||||
|
return a.bytes, nil
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("Asset %s not found", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MustAsset is like Asset but panics when Asset would return an error.
|
||||||
|
// It simplifies safe initialization of global variables.
|
||||||
|
func MustAsset(name string) []byte {
|
||||||
|
a, err := Asset(name)
|
||||||
|
if err != nil {
|
||||||
|
panic("asset: Asset(" + name + "): " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
|
// AssetInfo loads and returns the asset info for the given name.
|
||||||
|
// It returns an error if the asset could not be found or
|
||||||
|
// could not be loaded.
|
||||||
|
func AssetInfo(name string) (os.FileInfo, error) {
|
||||||
|
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||||
|
if f, ok := _bindata[cannonicalName]; ok {
|
||||||
|
a, err := f()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
|
||||||
|
}
|
||||||
|
return a.info, nil
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("AssetInfo %s not found", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AssetNames returns the names of the assets.
|
||||||
|
func AssetNames() []string {
|
||||||
|
names := make([]string, 0, len(_bindata))
|
||||||
|
for name := range _bindata {
|
||||||
|
names = append(names, name)
|
||||||
|
}
|
||||||
|
return names
|
||||||
|
}
|
||||||
|
|
||||||
|
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||||
|
var _bindata = map[string]func() (*asset, error){
|
||||||
|
"in/a/test.asset": inATestAsset,
|
||||||
|
"in/b/test.asset": inBTestAsset,
|
||||||
|
"in/c/test.asset": inCTestAsset,
|
||||||
|
"in/test.asset": inTestAsset,
|
||||||
|
}
|
||||||
|
|
||||||
|
// AssetDir returns the file names below a certain
|
||||||
|
// directory embedded in the file by go-bindata.
|
||||||
|
// For example if you run go-bindata on data/... and data contains the
|
||||||
|
// following hierarchy:
|
||||||
|
// data/
|
||||||
|
// foo.txt
|
||||||
|
// img/
|
||||||
|
// a.png
|
||||||
|
// b.png
|
||||||
|
// then AssetDir("data") would return []string{"foo.txt", "img"}
|
||||||
|
// AssetDir("data/img") would return []string{"a.png", "b.png"}
|
||||||
|
// AssetDir("foo.txt") and AssetDir("notexist") would return an error
|
||||||
|
// AssetDir("") will return []string{"data"}.
|
||||||
|
func AssetDir(name string) ([]string, error) {
|
||||||
|
node := _bintree
|
||||||
|
if len(name) != 0 {
|
||||||
|
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||||
|
pathList := strings.Split(cannonicalName, "/")
|
||||||
|
for _, p := range pathList {
|
||||||
|
node = node.Children[p]
|
||||||
|
if node == nil {
|
||||||
|
return nil, fmt.Errorf("Asset %s not found", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if node.Func != nil {
|
||||||
|
return nil, fmt.Errorf("Asset %s not found", name)
|
||||||
|
}
|
||||||
|
rv := make([]string, 0, len(node.Children))
|
||||||
|
for childName := range node.Children {
|
||||||
|
rv = append(rv, childName)
|
||||||
|
}
|
||||||
|
return rv, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type bintree struct {
|
||||||
|
Func func() (*asset, error)
|
||||||
|
Children map[string]*bintree
|
||||||
|
}
|
||||||
|
var _bintree = &bintree{nil, map[string]*bintree{
|
||||||
|
"in": &bintree{nil, map[string]*bintree{
|
||||||
|
"a": &bintree{nil, map[string]*bintree{
|
||||||
|
"test.asset": &bintree{inATestAsset, map[string]*bintree{}},
|
||||||
|
}},
|
||||||
|
"b": &bintree{nil, map[string]*bintree{
|
||||||
|
"test.asset": &bintree{inBTestAsset, map[string]*bintree{}},
|
||||||
|
}},
|
||||||
|
"c": &bintree{nil, map[string]*bintree{
|
||||||
|
"test.asset": &bintree{inCTestAsset, map[string]*bintree{}},
|
||||||
|
}},
|
||||||
|
"test.asset": &bintree{inTestAsset, map[string]*bintree{}},
|
||||||
|
}},
|
||||||
|
}}
|
||||||
|
|
||||||
|
// RestoreAsset restores an asset under the given directory
|
||||||
|
func RestoreAsset(dir, name string) error {
|
||||||
|
data, err := Asset(name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
info, err := AssetInfo(name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
// RestoreAssets restores an asset under the given directory recursively
|
||||||
var _bindata = map[string]func() []byte{
|
func RestoreAssets(dir, name string) error {
|
||||||
"in/b/test.asset": in_b_test_asset,
|
children, err := AssetDir(name)
|
||||||
"in/test.asset": in_test_asset,
|
// File
|
||||||
"in/a/test.asset": in_a_test_asset,
|
if err != nil {
|
||||||
"in/c/test.asset": in_c_test_asset,
|
return RestoreAsset(dir, name)
|
||||||
|
}
|
||||||
|
// Dir
|
||||||
|
for _, child := range children {
|
||||||
|
err = RestoreAssets(dir, filepath.Join(name, child))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func _filePath(dir, name string) string {
|
||||||
|
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||||
|
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
322
testdata/out/compress-nomemcopy.go
vendored
322
testdata/out/compress-nomemcopy.go
vendored
|
@ -1,88 +1,312 @@
|
||||||
|
// Code generated by go-bindata.
|
||||||
|
// sources:
|
||||||
|
// in/a/test.asset
|
||||||
|
// in/b/test.asset
|
||||||
|
// in/c/test.asset
|
||||||
|
// in/test.asset
|
||||||
|
// DO NOT EDIT!
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"io/ioutil"
|
||||||
"reflect"
|
"os"
|
||||||
"unsafe"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func bindata_read(data, name string) []byte {
|
func bindataRead(data, name string) ([]byte, error) {
|
||||||
var empty [0]byte
|
gz, err := gzip.NewReader(strings.NewReader(data))
|
||||||
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 {
|
if err != nil {
|
||||||
log.Fatalf("Read %q: %v", name, err)
|
return nil, fmt.Errorf("Read %q: %v", name, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
_, err = io.Copy(&buf, gz)
|
_, err = io.Copy(&buf, gz)
|
||||||
gz.Close()
|
clErr := gz.Close()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Read %q: %v", name, err)
|
return nil, fmt.Errorf("Read %q: %v", name, err)
|
||||||
|
}
|
||||||
|
if clErr != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return buf.Bytes()
|
return buf.Bytes(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
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"
|
type asset struct {
|
||||||
|
bytes []byte
|
||||||
func in_b_test_asset() []byte {
|
info os.FileInfo
|
||||||
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"
|
type bindataFileInfo struct {
|
||||||
|
name string
|
||||||
func in_test_asset() []byte {
|
size int64
|
||||||
return bindata_read(
|
mode os.FileMode
|
||||||
_in_test_asset,
|
modTime time.Time
|
||||||
"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 (fi bindataFileInfo) Name() string {
|
||||||
|
return fi.name
|
||||||
|
}
|
||||||
|
func (fi bindataFileInfo) Size() int64 {
|
||||||
|
return fi.size
|
||||||
|
}
|
||||||
|
func (fi bindataFileInfo) Mode() os.FileMode {
|
||||||
|
return fi.mode
|
||||||
|
}
|
||||||
|
func (fi bindataFileInfo) ModTime() time.Time {
|
||||||
|
return fi.modTime
|
||||||
|
}
|
||||||
|
func (fi bindataFileInfo) IsDir() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
func (fi bindataFileInfo) Sys() interface{} {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func in_a_test_asset() []byte {
|
var _inATestAsset = "\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"
|
||||||
return bindata_read(
|
|
||||||
_in_a_test_asset,
|
func inATestAssetBytes() ([]byte, error) {
|
||||||
|
return bindataRead(
|
||||||
|
_inATestAsset,
|
||||||
"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 inATestAsset() (*asset, error) {
|
||||||
|
bytes, err := inATestAssetBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
func in_c_test_asset() []byte {
|
info := bindataFileInfo{name: "in/a/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
|
||||||
return bindata_read(
|
a := &asset{bytes: bytes, info: info}
|
||||||
_in_c_test_asset,
|
return a, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var _inBTestAsset = "\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 inBTestAssetBytes() ([]byte, error) {
|
||||||
|
return bindataRead(
|
||||||
|
_inBTestAsset,
|
||||||
|
"in/b/test.asset",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func inBTestAsset() (*asset, error) {
|
||||||
|
bytes, err := inBTestAssetBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
info := bindataFileInfo{name: "in/b/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
|
||||||
|
a := &asset{bytes: bytes, info: info}
|
||||||
|
return a, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var _inCTestAsset = "\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 inCTestAssetBytes() ([]byte, error) {
|
||||||
|
return bindataRead(
|
||||||
|
_inCTestAsset,
|
||||||
"in/c/test.asset",
|
"in/c/test.asset",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func inCTestAsset() (*asset, error) {
|
||||||
|
bytes, err := inCTestAssetBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
info := bindataFileInfo{name: "in/c/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
|
||||||
|
a := &asset{bytes: bytes, info: info}
|
||||||
|
return a, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var _inTestAsset = "\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 inTestAssetBytes() ([]byte, error) {
|
||||||
|
return bindataRead(
|
||||||
|
_inTestAsset,
|
||||||
|
"in/test.asset",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func inTestAsset() (*asset, error) {
|
||||||
|
bytes, err := inTestAssetBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
info := bindataFileInfo{name: "in/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
|
||||||
|
a := &asset{bytes: bytes, info: info}
|
||||||
|
return a, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Asset loads and returns the asset for the given name.
|
// Asset loads and returns the asset for the given name.
|
||||||
// This returns nil of the asset could not be found.
|
// It returns an error if the asset could not be found or
|
||||||
func Asset(name string) []byte {
|
// could not be loaded.
|
||||||
if f, ok := _bindata[name]; ok {
|
func Asset(name string) ([]byte, error) {
|
||||||
return f()
|
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||||
|
if f, ok := _bindata[cannonicalName]; ok {
|
||||||
|
a, err := f()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
|
||||||
|
}
|
||||||
|
return a.bytes, nil
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("Asset %s not found", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MustAsset is like Asset but panics when Asset would return an error.
|
||||||
|
// It simplifies safe initialization of global variables.
|
||||||
|
func MustAsset(name string) []byte {
|
||||||
|
a, err := Asset(name)
|
||||||
|
if err != nil {
|
||||||
|
panic("asset: Asset(" + name + "): " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
|
// AssetInfo loads and returns the asset info for the given name.
|
||||||
|
// It returns an error if the asset could not be found or
|
||||||
|
// could not be loaded.
|
||||||
|
func AssetInfo(name string) (os.FileInfo, error) {
|
||||||
|
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||||
|
if f, ok := _bindata[cannonicalName]; ok {
|
||||||
|
a, err := f()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
|
||||||
|
}
|
||||||
|
return a.info, nil
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("AssetInfo %s not found", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AssetNames returns the names of the assets.
|
||||||
|
func AssetNames() []string {
|
||||||
|
names := make([]string, 0, len(_bindata))
|
||||||
|
for name := range _bindata {
|
||||||
|
names = append(names, name)
|
||||||
|
}
|
||||||
|
return names
|
||||||
|
}
|
||||||
|
|
||||||
|
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||||
|
var _bindata = map[string]func() (*asset, error){
|
||||||
|
"in/a/test.asset": inATestAsset,
|
||||||
|
"in/b/test.asset": inBTestAsset,
|
||||||
|
"in/c/test.asset": inCTestAsset,
|
||||||
|
"in/test.asset": inTestAsset,
|
||||||
|
}
|
||||||
|
|
||||||
|
// AssetDir returns the file names below a certain
|
||||||
|
// directory embedded in the file by go-bindata.
|
||||||
|
// For example if you run go-bindata on data/... and data contains the
|
||||||
|
// following hierarchy:
|
||||||
|
// data/
|
||||||
|
// foo.txt
|
||||||
|
// img/
|
||||||
|
// a.png
|
||||||
|
// b.png
|
||||||
|
// then AssetDir("data") would return []string{"foo.txt", "img"}
|
||||||
|
// AssetDir("data/img") would return []string{"a.png", "b.png"}
|
||||||
|
// AssetDir("foo.txt") and AssetDir("notexist") would return an error
|
||||||
|
// AssetDir("") will return []string{"data"}.
|
||||||
|
func AssetDir(name string) ([]string, error) {
|
||||||
|
node := _bintree
|
||||||
|
if len(name) != 0 {
|
||||||
|
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||||
|
pathList := strings.Split(cannonicalName, "/")
|
||||||
|
for _, p := range pathList {
|
||||||
|
node = node.Children[p]
|
||||||
|
if node == nil {
|
||||||
|
return nil, fmt.Errorf("Asset %s not found", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if node.Func != nil {
|
||||||
|
return nil, fmt.Errorf("Asset %s not found", name)
|
||||||
|
}
|
||||||
|
rv := make([]string, 0, len(node.Children))
|
||||||
|
for childName := range node.Children {
|
||||||
|
rv = append(rv, childName)
|
||||||
|
}
|
||||||
|
return rv, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type bintree struct {
|
||||||
|
Func func() (*asset, error)
|
||||||
|
Children map[string]*bintree
|
||||||
|
}
|
||||||
|
var _bintree = &bintree{nil, map[string]*bintree{
|
||||||
|
"in": &bintree{nil, map[string]*bintree{
|
||||||
|
"a": &bintree{nil, map[string]*bintree{
|
||||||
|
"test.asset": &bintree{inATestAsset, map[string]*bintree{}},
|
||||||
|
}},
|
||||||
|
"b": &bintree{nil, map[string]*bintree{
|
||||||
|
"test.asset": &bintree{inBTestAsset, map[string]*bintree{}},
|
||||||
|
}},
|
||||||
|
"c": &bintree{nil, map[string]*bintree{
|
||||||
|
"test.asset": &bintree{inCTestAsset, map[string]*bintree{}},
|
||||||
|
}},
|
||||||
|
"test.asset": &bintree{inTestAsset, map[string]*bintree{}},
|
||||||
|
}},
|
||||||
|
}}
|
||||||
|
|
||||||
|
// RestoreAsset restores an asset under the given directory
|
||||||
|
func RestoreAsset(dir, name string) error {
|
||||||
|
data, err := Asset(name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
info, err := AssetInfo(name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
// RestoreAssets restores an asset under the given directory recursively
|
||||||
var _bindata = map[string]func() []byte{
|
func RestoreAssets(dir, name string) error {
|
||||||
"in/b/test.asset": in_b_test_asset,
|
children, err := AssetDir(name)
|
||||||
"in/test.asset": in_test_asset,
|
// File
|
||||||
"in/a/test.asset": in_a_test_asset,
|
if err != nil {
|
||||||
"in/c/test.asset": in_c_test_asset,
|
return RestoreAsset(dir, name)
|
||||||
|
}
|
||||||
|
// Dir
|
||||||
|
for _, child := range children {
|
||||||
|
err = RestoreAssets(dir, filepath.Join(name, child))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func _filePath(dir, name string) string {
|
||||||
|
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||||
|
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
289
testdata/out/debug.go
vendored
289
testdata/out/debug.go
vendored
|
@ -1,80 +1,263 @@
|
||||||
|
// Code generated by go-bindata.
|
||||||
|
// sources:
|
||||||
|
// in/a/test.asset
|
||||||
|
// in/b/test.asset
|
||||||
|
// in/c/test.asset
|
||||||
|
// in/test.asset
|
||||||
|
// DO NOT EDIT!
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"fmt"
|
||||||
"io"
|
"io/ioutil"
|
||||||
"log"
|
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// bindata_read reads the given file from disk.
|
// bindataRead reads the given file from disk. It returns an error on failure.
|
||||||
// It panics if anything went wrong.
|
func bindataRead(path, name string) ([]byte, error) {
|
||||||
func bindata_read(path, name string) []byte {
|
buf, err := ioutil.ReadFile(path)
|
||||||
fd, err := os.Open(path)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Read %s: %v", name, err)
|
err = fmt.Errorf("Error reading asset %s at %s: %v", name, path, err)
|
||||||
|
}
|
||||||
|
return buf, err
|
||||||
|
}
|
||||||
|
|
||||||
|
type asset struct {
|
||||||
|
bytes []byte
|
||||||
|
info os.FileInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
// inATestAsset reads file data from disk. It returns an error on failure.
|
||||||
|
func inATestAsset() (*asset, error) {
|
||||||
|
path := "/home/ts/code/go/src/git.kirsle.net/go/bindata/testdata/in/a/test.asset"
|
||||||
|
name := "in/a/test.asset"
|
||||||
|
bytes, err := bindataRead(path, name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer fd.Close()
|
fi, err := os.Stat(path)
|
||||||
|
|
||||||
var buf bytes.Buffer
|
|
||||||
_, err = io.Copy(&buf, fd)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Read %s: %v", name, err)
|
err = fmt.Errorf("Error reading asset info %s at %s: %v", name, path, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return buf.Bytes()
|
a := &asset{bytes: bytes, info: fi}
|
||||||
|
return a, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// in_b_test_asset reads file data from disk.
|
// inBTestAsset reads file data from disk. It returns an error on failure.
|
||||||
// It panics if something went wrong in the process.
|
func inBTestAsset() (*asset, error) {
|
||||||
func in_b_test_asset() []byte {
|
path := "/home/ts/code/go/src/git.kirsle.net/go/bindata/testdata/in/b/test.asset"
|
||||||
return bindata_read(
|
name := "in/b/test.asset"
|
||||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/b/test.asset",
|
bytes, err := bindataRead(path, name)
|
||||||
"in/b/test.asset",
|
if err != nil {
|
||||||
)
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
fi, err := os.Stat(path)
|
||||||
|
if err != nil {
|
||||||
|
err = fmt.Errorf("Error reading asset info %s at %s: %v", name, path, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
a := &asset{bytes: bytes, info: fi}
|
||||||
|
return a, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// in_test_asset reads file data from disk.
|
// inCTestAsset reads file data from disk. It returns an error on failure.
|
||||||
// It panics if something went wrong in the process.
|
func inCTestAsset() (*asset, error) {
|
||||||
func in_test_asset() []byte {
|
path := "/home/ts/code/go/src/git.kirsle.net/go/bindata/testdata/in/c/test.asset"
|
||||||
return bindata_read(
|
name := "in/c/test.asset"
|
||||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/test.asset",
|
bytes, err := bindataRead(path, name)
|
||||||
"in/test.asset",
|
if err != nil {
|
||||||
)
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
fi, err := os.Stat(path)
|
||||||
|
if err != nil {
|
||||||
|
err = fmt.Errorf("Error reading asset info %s at %s: %v", name, path, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
a := &asset{bytes: bytes, info: fi}
|
||||||
|
return a, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// in_a_test_asset reads file data from disk.
|
// inTestAsset reads file data from disk. It returns an error on failure.
|
||||||
// It panics if something went wrong in the process.
|
func inTestAsset() (*asset, error) {
|
||||||
func in_a_test_asset() []byte {
|
path := "/home/ts/code/go/src/git.kirsle.net/go/bindata/testdata/in/test.asset"
|
||||||
return bindata_read(
|
name := "in/test.asset"
|
||||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/a/test.asset",
|
bytes, err := bindataRead(path, name)
|
||||||
"in/a/test.asset",
|
if err != nil {
|
||||||
)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// in_c_test_asset reads file data from disk.
|
fi, err := os.Stat(path)
|
||||||
// It panics if something went wrong in the process.
|
if err != nil {
|
||||||
func in_c_test_asset() []byte {
|
err = fmt.Errorf("Error reading asset info %s at %s: %v", name, path, err)
|
||||||
return bindata_read(
|
}
|
||||||
"/a/code/go/src/github.com/jteeuwen/go-bindata/testdata/in/c/test.asset",
|
|
||||||
"in/c/test.asset",
|
a := &asset{bytes: bytes, info: fi}
|
||||||
)
|
return a, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Asset loads and returns the asset for the given name.
|
// Asset loads and returns the asset for the given name.
|
||||||
// This returns nil of the asset could not be found.
|
// It returns an error if the asset could not be found or
|
||||||
func Asset(name string) []byte {
|
// could not be loaded.
|
||||||
if f, ok := _bindata[name]; ok {
|
func Asset(name string) ([]byte, error) {
|
||||||
return f()
|
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||||
|
if f, ok := _bindata[cannonicalName]; ok {
|
||||||
|
a, err := f()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
|
||||||
|
}
|
||||||
|
return a.bytes, nil
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("Asset %s not found", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MustAsset is like Asset but panics when Asset would return an error.
|
||||||
|
// It simplifies safe initialization of global variables.
|
||||||
|
func MustAsset(name string) []byte {
|
||||||
|
a, err := Asset(name)
|
||||||
|
if err != nil {
|
||||||
|
panic("asset: Asset(" + name + "): " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
|
// AssetInfo loads and returns the asset info for the given name.
|
||||||
|
// It returns an error if the asset could not be found or
|
||||||
|
// could not be loaded.
|
||||||
|
func AssetInfo(name string) (os.FileInfo, error) {
|
||||||
|
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||||
|
if f, ok := _bindata[cannonicalName]; ok {
|
||||||
|
a, err := f()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
|
||||||
|
}
|
||||||
|
return a.info, nil
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("AssetInfo %s not found", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AssetNames returns the names of the assets.
|
||||||
|
func AssetNames() []string {
|
||||||
|
names := make([]string, 0, len(_bindata))
|
||||||
|
for name := range _bindata {
|
||||||
|
names = append(names, name)
|
||||||
|
}
|
||||||
|
return names
|
||||||
|
}
|
||||||
|
|
||||||
|
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||||
|
var _bindata = map[string]func() (*asset, error){
|
||||||
|
"in/a/test.asset": inATestAsset,
|
||||||
|
"in/b/test.asset": inBTestAsset,
|
||||||
|
"in/c/test.asset": inCTestAsset,
|
||||||
|
"in/test.asset": inTestAsset,
|
||||||
|
}
|
||||||
|
|
||||||
|
// AssetDir returns the file names below a certain
|
||||||
|
// directory embedded in the file by go-bindata.
|
||||||
|
// For example if you run go-bindata on data/... and data contains the
|
||||||
|
// following hierarchy:
|
||||||
|
// data/
|
||||||
|
// foo.txt
|
||||||
|
// img/
|
||||||
|
// a.png
|
||||||
|
// b.png
|
||||||
|
// then AssetDir("data") would return []string{"foo.txt", "img"}
|
||||||
|
// AssetDir("data/img") would return []string{"a.png", "b.png"}
|
||||||
|
// AssetDir("foo.txt") and AssetDir("notexist") would return an error
|
||||||
|
// AssetDir("") will return []string{"data"}.
|
||||||
|
func AssetDir(name string) ([]string, error) {
|
||||||
|
node := _bintree
|
||||||
|
if len(name) != 0 {
|
||||||
|
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||||
|
pathList := strings.Split(cannonicalName, "/")
|
||||||
|
for _, p := range pathList {
|
||||||
|
node = node.Children[p]
|
||||||
|
if node == nil {
|
||||||
|
return nil, fmt.Errorf("Asset %s not found", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if node.Func != nil {
|
||||||
|
return nil, fmt.Errorf("Asset %s not found", name)
|
||||||
|
}
|
||||||
|
rv := make([]string, 0, len(node.Children))
|
||||||
|
for childName := range node.Children {
|
||||||
|
rv = append(rv, childName)
|
||||||
|
}
|
||||||
|
return rv, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type bintree struct {
|
||||||
|
Func func() (*asset, error)
|
||||||
|
Children map[string]*bintree
|
||||||
|
}
|
||||||
|
var _bintree = &bintree{nil, map[string]*bintree{
|
||||||
|
"in": &bintree{nil, map[string]*bintree{
|
||||||
|
"a": &bintree{nil, map[string]*bintree{
|
||||||
|
"test.asset": &bintree{inATestAsset, map[string]*bintree{}},
|
||||||
|
}},
|
||||||
|
"b": &bintree{nil, map[string]*bintree{
|
||||||
|
"test.asset": &bintree{inBTestAsset, map[string]*bintree{}},
|
||||||
|
}},
|
||||||
|
"c": &bintree{nil, map[string]*bintree{
|
||||||
|
"test.asset": &bintree{inCTestAsset, map[string]*bintree{}},
|
||||||
|
}},
|
||||||
|
"test.asset": &bintree{inTestAsset, map[string]*bintree{}},
|
||||||
|
}},
|
||||||
|
}}
|
||||||
|
|
||||||
|
// RestoreAsset restores an asset under the given directory
|
||||||
|
func RestoreAsset(dir, name string) error {
|
||||||
|
data, err := Asset(name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
info, err := AssetInfo(name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
// RestoreAssets restores an asset under the given directory recursively
|
||||||
var _bindata = map[string]func() []byte{
|
func RestoreAssets(dir, name string) error {
|
||||||
"in/b/test.asset": in_b_test_asset,
|
children, err := AssetDir(name)
|
||||||
"in/test.asset": in_test_asset,
|
// File
|
||||||
"in/a/test.asset": in_a_test_asset,
|
if err != nil {
|
||||||
"in/c/test.asset": in_c_test_asset,
|
return RestoreAsset(dir, name)
|
||||||
|
}
|
||||||
|
// Dir
|
||||||
|
for _, child := range children {
|
||||||
|
err = RestoreAssets(dir, filepath.Join(name, child))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func _filePath(dir, name string) string {
|
||||||
|
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||||
|
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
259
testdata/out/debug.go-bindata
vendored
Normal file
259
testdata/out/debug.go-bindata
vendored
Normal file
|
@ -0,0 +1,259 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"strings"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
"path/filepath"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
|
type asset struct {
|
||||||
|
bytes []byte
|
||||||
|
info os.FileInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
// in_a_test_asset reads file data from disk. It returns an error on failure.
|
||||||
|
func in_a_test_asset() (*asset, error) {
|
||||||
|
path := "/Users/tamird/src/go/src/git.kirsle.net/go/bindata/testdata/in/a/test.asset"
|
||||||
|
name := "in/a/test.asset"
|
||||||
|
bytes, err := bindata_read(path, name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
fi, err := os.Stat(path)
|
||||||
|
if err != nil {
|
||||||
|
err = fmt.Errorf("Error reading asset info %s at %s: %v", name, path, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
a := &asset{bytes: bytes, info: fi}
|
||||||
|
return a, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// in_b_test_asset reads file data from disk. It returns an error on failure.
|
||||||
|
func in_b_test_asset() (*asset, error) {
|
||||||
|
path := "/Users/tamird/src/go/src/git.kirsle.net/go/bindata/testdata/in/b/test.asset"
|
||||||
|
name := "in/b/test.asset"
|
||||||
|
bytes, err := bindata_read(path, name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
fi, err := os.Stat(path)
|
||||||
|
if err != nil {
|
||||||
|
err = fmt.Errorf("Error reading asset info %s at %s: %v", name, path, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
a := &asset{bytes: bytes, info: fi}
|
||||||
|
return a, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// in_c_test_asset reads file data from disk. It returns an error on failure.
|
||||||
|
func in_c_test_asset() (*asset, error) {
|
||||||
|
path := "/Users/tamird/src/go/src/git.kirsle.net/go/bindata/testdata/in/c/test.asset"
|
||||||
|
name := "in/c/test.asset"
|
||||||
|
bytes, err := bindata_read(path, name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
fi, err := os.Stat(path)
|
||||||
|
if err != nil {
|
||||||
|
err = fmt.Errorf("Error reading asset info %s at %s: %v", name, path, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
a := &asset{bytes: bytes, info: fi}
|
||||||
|
return a, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// in_test_asset reads file data from disk. It returns an error on failure.
|
||||||
|
func in_test_asset() (*asset, error) {
|
||||||
|
path := "/Users/tamird/src/go/src/git.kirsle.net/go/bindata/testdata/in/test.asset"
|
||||||
|
name := "in/test.asset"
|
||||||
|
bytes, err := bindata_read(path, name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
fi, err := os.Stat(path)
|
||||||
|
if err != nil {
|
||||||
|
err = fmt.Errorf("Error reading asset info %s at %s: %v", name, path, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
a := &asset{bytes: bytes, info: fi}
|
||||||
|
return a, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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) {
|
||||||
|
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||||
|
if f, ok := _bindata[cannonicalName]; ok {
|
||||||
|
a, err := f()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
|
||||||
|
}
|
||||||
|
return a.bytes, nil
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("Asset %s not found", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MustAsset is like Asset but panics when Asset would return an error.
|
||||||
|
// It simplifies safe initialization of global variables.
|
||||||
|
func MustAsset(name string) []byte {
|
||||||
|
a, err := Asset(name)
|
||||||
|
if (err != nil) {
|
||||||
|
panic("asset: Asset(" + name + "): " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
|
// AssetInfo loads and returns the asset info for the given name.
|
||||||
|
// It returns an error if the asset could not be found or
|
||||||
|
// could not be loaded.
|
||||||
|
func AssetInfo(name string) (os.FileInfo, error) {
|
||||||
|
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||||
|
if f, ok := _bindata[cannonicalName]; ok {
|
||||||
|
a, err := f()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
|
||||||
|
}
|
||||||
|
return a.info, nil
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("AssetInfo %s not found", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AssetNames returns the names of the assets.
|
||||||
|
func AssetNames() []string {
|
||||||
|
names := make([]string, 0, len(_bindata))
|
||||||
|
for name := range _bindata {
|
||||||
|
names = append(names, name)
|
||||||
|
}
|
||||||
|
return names
|
||||||
|
}
|
||||||
|
|
||||||
|
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||||
|
var _bindata = map[string]func() (*asset, error){
|
||||||
|
"in/a/test.asset": in_a_test_asset,
|
||||||
|
"in/b/test.asset": in_b_test_asset,
|
||||||
|
"in/c/test.asset": in_c_test_asset,
|
||||||
|
"in/test.asset": in_test_asset,
|
||||||
|
}
|
||||||
|
|
||||||
|
// AssetDir returns the file names below a certain
|
||||||
|
// directory embedded in the file by go-bindata.
|
||||||
|
// For example if you run go-bindata on data/... and data contains the
|
||||||
|
// following hierarchy:
|
||||||
|
// data/
|
||||||
|
// foo.txt
|
||||||
|
// img/
|
||||||
|
// a.png
|
||||||
|
// b.png
|
||||||
|
// then AssetDir("data") would return []string{"foo.txt", "img"}
|
||||||
|
// AssetDir("data/img") would return []string{"a.png", "b.png"}
|
||||||
|
// AssetDir("foo.txt") and AssetDir("notexist") would return an error
|
||||||
|
// AssetDir("") will return []string{"data"}.
|
||||||
|
func AssetDir(name string) ([]string, error) {
|
||||||
|
node := _bintree
|
||||||
|
if len(name) != 0 {
|
||||||
|
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||||
|
pathList := strings.Split(cannonicalName, "/")
|
||||||
|
for _, p := range pathList {
|
||||||
|
node = node.Children[p]
|
||||||
|
if node == nil {
|
||||||
|
return nil, fmt.Errorf("Asset %s not found", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if node.Func != nil {
|
||||||
|
return nil, fmt.Errorf("Asset %s not found", name)
|
||||||
|
}
|
||||||
|
rv := make([]string, 0, len(node.Children))
|
||||||
|
for name := range node.Children {
|
||||||
|
rv = append(rv, name)
|
||||||
|
}
|
||||||
|
return rv, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type _bintree_t struct {
|
||||||
|
Func func() (*asset, error)
|
||||||
|
Children map[string]*_bintree_t
|
||||||
|
}
|
||||||
|
var _bintree = &_bintree_t{nil, map[string]*_bintree_t{
|
||||||
|
"in": &_bintree_t{nil, map[string]*_bintree_t{
|
||||||
|
"a": &_bintree_t{nil, map[string]*_bintree_t{
|
||||||
|
"test.asset": &_bintree_t{in_a_test_asset, map[string]*_bintree_t{
|
||||||
|
}},
|
||||||
|
}},
|
||||||
|
"b": &_bintree_t{nil, map[string]*_bintree_t{
|
||||||
|
"test.asset": &_bintree_t{in_b_test_asset, map[string]*_bintree_t{
|
||||||
|
}},
|
||||||
|
}},
|
||||||
|
"c": &_bintree_t{nil, map[string]*_bintree_t{
|
||||||
|
"test.asset": &_bintree_t{in_c_test_asset, map[string]*_bintree_t{
|
||||||
|
}},
|
||||||
|
}},
|
||||||
|
"test.asset": &_bintree_t{in_test_asset, map[string]*_bintree_t{
|
||||||
|
}},
|
||||||
|
}},
|
||||||
|
}}
|
||||||
|
|
||||||
|
// Restore an asset under the given directory
|
||||||
|
func RestoreAsset(dir, name string) error {
|
||||||
|
data, err := Asset(name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
info, err := AssetInfo(name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = os.MkdirAll(_filePath(dir, path.Dir(name)), os.FileMode(0755))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Restore assets under the given directory recursively
|
||||||
|
func RestoreAssets(dir, name string) error {
|
||||||
|
children, err := AssetDir(name)
|
||||||
|
if err != nil { // File
|
||||||
|
return RestoreAsset(dir, name)
|
||||||
|
} else { // Dir
|
||||||
|
for _, child := range children {
|
||||||
|
err = RestoreAssets(dir, path.Join(name, child))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func _filePath(dir, name string) string {
|
||||||
|
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||||
|
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
|
||||||
|
}
|
||||||
|
|
292
testdata/out/nocompress-memcopy.go
vendored
292
testdata/out/nocompress-memcopy.go
vendored
|
@ -1,46 +1,280 @@
|
||||||
|
// Code generated by go-bindata.
|
||||||
|
// sources:
|
||||||
|
// in/a/test.asset
|
||||||
|
// in/b/test.asset
|
||||||
|
// in/c/test.asset
|
||||||
|
// in/test.asset
|
||||||
|
// DO NOT EDIT!
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
func in_b_test_asset() []byte {
|
import (
|
||||||
return []byte{
|
"fmt"
|
||||||
0x2f, 0x2f, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x66, 0x69,
|
"io/ioutil"
|
||||||
0x6c, 0x65, 0x0a,
|
"os"
|
||||||
}
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
type asset struct {
|
||||||
|
bytes []byte
|
||||||
|
info os.FileInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
func in_test_asset() []byte {
|
type bindataFileInfo struct {
|
||||||
return []byte{
|
name string
|
||||||
0x2f, 0x2f, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x66, 0x69,
|
size int64
|
||||||
0x6c, 0x65, 0x0a,
|
mode os.FileMode
|
||||||
}
|
modTime time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func in_a_test_asset() []byte {
|
func (fi bindataFileInfo) Name() string {
|
||||||
return []byte{
|
return fi.name
|
||||||
0x2f, 0x2f, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x66, 0x69,
|
}
|
||||||
0x6c, 0x65, 0x0a,
|
func (fi bindataFileInfo) Size() int64 {
|
||||||
}
|
return fi.size
|
||||||
|
}
|
||||||
|
func (fi bindataFileInfo) Mode() os.FileMode {
|
||||||
|
return fi.mode
|
||||||
|
}
|
||||||
|
func (fi bindataFileInfo) ModTime() time.Time {
|
||||||
|
return fi.modTime
|
||||||
|
}
|
||||||
|
func (fi bindataFileInfo) IsDir() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
func (fi bindataFileInfo) Sys() interface{} {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func in_c_test_asset() []byte {
|
var _inATestAsset = []byte(`// sample file
|
||||||
return []byte{
|
`)
|
||||||
0x2f, 0x2f, 0x20, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x20, 0x66, 0x69,
|
|
||||||
0x6c, 0x65, 0x0a,
|
func inATestAssetBytes() ([]byte, error) {
|
||||||
|
return _inATestAsset, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func inATestAsset() (*asset, error) {
|
||||||
|
bytes, err := inATestAssetBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
info := bindataFileInfo{name: "in/a/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
|
||||||
|
a := &asset{bytes: bytes, info: info}
|
||||||
|
return a, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var _inBTestAsset = []byte(`// sample file
|
||||||
|
`)
|
||||||
|
|
||||||
|
func inBTestAssetBytes() ([]byte, error) {
|
||||||
|
return _inBTestAsset, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func inBTestAsset() (*asset, error) {
|
||||||
|
bytes, err := inBTestAssetBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
info := bindataFileInfo{name: "in/b/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
|
||||||
|
a := &asset{bytes: bytes, info: info}
|
||||||
|
return a, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var _inCTestAsset = []byte(`// sample file
|
||||||
|
`)
|
||||||
|
|
||||||
|
func inCTestAssetBytes() ([]byte, error) {
|
||||||
|
return _inCTestAsset, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func inCTestAsset() (*asset, error) {
|
||||||
|
bytes, err := inCTestAssetBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
info := bindataFileInfo{name: "in/c/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
|
||||||
|
a := &asset{bytes: bytes, info: info}
|
||||||
|
return a, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var _inTestAsset = []byte(`// sample file
|
||||||
|
`)
|
||||||
|
|
||||||
|
func inTestAssetBytes() ([]byte, error) {
|
||||||
|
return _inTestAsset, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func inTestAsset() (*asset, error) {
|
||||||
|
bytes, err := inTestAssetBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
info := bindataFileInfo{name: "in/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
|
||||||
|
a := &asset{bytes: bytes, info: info}
|
||||||
|
return a, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Asset loads and returns the asset for the given name.
|
// Asset loads and returns the asset for the given name.
|
||||||
// This returns nil of the asset could not be found.
|
// It returns an error if the asset could not be found or
|
||||||
func Asset(name string) []byte {
|
// could not be loaded.
|
||||||
if f, ok := _bindata[name]; ok {
|
func Asset(name string) ([]byte, error) {
|
||||||
return f()
|
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||||
|
if f, ok := _bindata[cannonicalName]; ok {
|
||||||
|
a, err := f()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
|
||||||
|
}
|
||||||
|
return a.bytes, nil
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("Asset %s not found", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MustAsset is like Asset but panics when Asset would return an error.
|
||||||
|
// It simplifies safe initialization of global variables.
|
||||||
|
func MustAsset(name string) []byte {
|
||||||
|
a, err := Asset(name)
|
||||||
|
if err != nil {
|
||||||
|
panic("asset: Asset(" + name + "): " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
|
// AssetInfo loads and returns the asset info for the given name.
|
||||||
|
// It returns an error if the asset could not be found or
|
||||||
|
// could not be loaded.
|
||||||
|
func AssetInfo(name string) (os.FileInfo, error) {
|
||||||
|
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||||
|
if f, ok := _bindata[cannonicalName]; ok {
|
||||||
|
a, err := f()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
|
||||||
|
}
|
||||||
|
return a.info, nil
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("AssetInfo %s not found", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AssetNames returns the names of the assets.
|
||||||
|
func AssetNames() []string {
|
||||||
|
names := make([]string, 0, len(_bindata))
|
||||||
|
for name := range _bindata {
|
||||||
|
names = append(names, name)
|
||||||
|
}
|
||||||
|
return names
|
||||||
|
}
|
||||||
|
|
||||||
|
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||||
|
var _bindata = map[string]func() (*asset, error){
|
||||||
|
"in/a/test.asset": inATestAsset,
|
||||||
|
"in/b/test.asset": inBTestAsset,
|
||||||
|
"in/c/test.asset": inCTestAsset,
|
||||||
|
"in/test.asset": inTestAsset,
|
||||||
|
}
|
||||||
|
|
||||||
|
// AssetDir returns the file names below a certain
|
||||||
|
// directory embedded in the file by go-bindata.
|
||||||
|
// For example if you run go-bindata on data/... and data contains the
|
||||||
|
// following hierarchy:
|
||||||
|
// data/
|
||||||
|
// foo.txt
|
||||||
|
// img/
|
||||||
|
// a.png
|
||||||
|
// b.png
|
||||||
|
// then AssetDir("data") would return []string{"foo.txt", "img"}
|
||||||
|
// AssetDir("data/img") would return []string{"a.png", "b.png"}
|
||||||
|
// AssetDir("foo.txt") and AssetDir("notexist") would return an error
|
||||||
|
// AssetDir("") will return []string{"data"}.
|
||||||
|
func AssetDir(name string) ([]string, error) {
|
||||||
|
node := _bintree
|
||||||
|
if len(name) != 0 {
|
||||||
|
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||||
|
pathList := strings.Split(cannonicalName, "/")
|
||||||
|
for _, p := range pathList {
|
||||||
|
node = node.Children[p]
|
||||||
|
if node == nil {
|
||||||
|
return nil, fmt.Errorf("Asset %s not found", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if node.Func != nil {
|
||||||
|
return nil, fmt.Errorf("Asset %s not found", name)
|
||||||
|
}
|
||||||
|
rv := make([]string, 0, len(node.Children))
|
||||||
|
for childName := range node.Children {
|
||||||
|
rv = append(rv, childName)
|
||||||
|
}
|
||||||
|
return rv, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type bintree struct {
|
||||||
|
Func func() (*asset, error)
|
||||||
|
Children map[string]*bintree
|
||||||
|
}
|
||||||
|
var _bintree = &bintree{nil, map[string]*bintree{
|
||||||
|
"in": &bintree{nil, map[string]*bintree{
|
||||||
|
"a": &bintree{nil, map[string]*bintree{
|
||||||
|
"test.asset": &bintree{inATestAsset, map[string]*bintree{}},
|
||||||
|
}},
|
||||||
|
"b": &bintree{nil, map[string]*bintree{
|
||||||
|
"test.asset": &bintree{inBTestAsset, map[string]*bintree{}},
|
||||||
|
}},
|
||||||
|
"c": &bintree{nil, map[string]*bintree{
|
||||||
|
"test.asset": &bintree{inCTestAsset, map[string]*bintree{}},
|
||||||
|
}},
|
||||||
|
"test.asset": &bintree{inTestAsset, map[string]*bintree{}},
|
||||||
|
}},
|
||||||
|
}}
|
||||||
|
|
||||||
|
// RestoreAsset restores an asset under the given directory
|
||||||
|
func RestoreAsset(dir, name string) error {
|
||||||
|
data, err := Asset(name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
info, err := AssetInfo(name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
// RestoreAssets restores an asset under the given directory recursively
|
||||||
var _bindata = map[string]func() []byte{
|
func RestoreAssets(dir, name string) error {
|
||||||
"in/b/test.asset": in_b_test_asset,
|
children, err := AssetDir(name)
|
||||||
"in/test.asset": in_test_asset,
|
// File
|
||||||
"in/a/test.asset": in_a_test_asset,
|
if err != nil {
|
||||||
"in/c/test.asset": in_c_test_asset,
|
return RestoreAsset(dir, name)
|
||||||
|
}
|
||||||
|
// Dir
|
||||||
|
for _, child := range children {
|
||||||
|
err = RestoreAssets(dir, filepath.Join(name, child))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func _filePath(dir, name string) string {
|
||||||
|
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||||
|
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
300
testdata/out/nocompress-nomemcopy.go
vendored
300
testdata/out/nocompress-nomemcopy.go
vendored
|
@ -1,11 +1,25 @@
|
||||||
|
// Code generated by go-bindata.
|
||||||
|
// sources:
|
||||||
|
// in/a/test.asset
|
||||||
|
// in/b/test.asset
|
||||||
|
// in/c/test.asset
|
||||||
|
// in/test.asset
|
||||||
|
// DO NOT EDIT!
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
func bindata_read(data, name string) []byte {
|
func bindataRead(data, name string) ([]byte, error) {
|
||||||
var empty [0]byte
|
var empty [0]byte
|
||||||
sx := (*reflect.StringHeader)(unsafe.Pointer(&data))
|
sx := (*reflect.StringHeader)(unsafe.Pointer(&data))
|
||||||
b := empty[:]
|
b := empty[:]
|
||||||
|
@ -13,58 +27,276 @@ func bindata_read(data, name string) []byte {
|
||||||
bx.Data = sx.Data
|
bx.Data = sx.Data
|
||||||
bx.Len = len(data)
|
bx.Len = len(data)
|
||||||
bx.Cap = bx.Len
|
bx.Cap = bx.Len
|
||||||
return b
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var _in_b_test_asset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a"
|
type asset struct {
|
||||||
|
bytes []byte
|
||||||
func in_b_test_asset() []byte {
|
info os.FileInfo
|
||||||
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"
|
type bindataFileInfo struct {
|
||||||
|
name string
|
||||||
func in_test_asset() []byte {
|
size int64
|
||||||
return bindata_read(
|
mode os.FileMode
|
||||||
_in_test_asset,
|
modTime time.Time
|
||||||
"in/test.asset",
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _in_a_test_asset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a"
|
func (fi bindataFileInfo) Name() string {
|
||||||
|
return fi.name
|
||||||
|
}
|
||||||
|
func (fi bindataFileInfo) Size() int64 {
|
||||||
|
return fi.size
|
||||||
|
}
|
||||||
|
func (fi bindataFileInfo) Mode() os.FileMode {
|
||||||
|
return fi.mode
|
||||||
|
}
|
||||||
|
func (fi bindataFileInfo) ModTime() time.Time {
|
||||||
|
return fi.modTime
|
||||||
|
}
|
||||||
|
func (fi bindataFileInfo) IsDir() bool {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
func (fi bindataFileInfo) Sys() interface{} {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func in_a_test_asset() []byte {
|
var _inATestAsset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a"
|
||||||
return bindata_read(
|
|
||||||
_in_a_test_asset,
|
func inATestAssetBytes() ([]byte, error) {
|
||||||
|
return bindataRead(
|
||||||
|
_inATestAsset,
|
||||||
"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 inATestAsset() (*asset, error) {
|
||||||
|
bytes, err := inATestAssetBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
func in_c_test_asset() []byte {
|
info := bindataFileInfo{name: "in/a/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
|
||||||
return bindata_read(
|
a := &asset{bytes: bytes, info: info}
|
||||||
_in_c_test_asset,
|
return a, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var _inBTestAsset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a"
|
||||||
|
|
||||||
|
func inBTestAssetBytes() ([]byte, error) {
|
||||||
|
return bindataRead(
|
||||||
|
_inBTestAsset,
|
||||||
|
"in/b/test.asset",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func inBTestAsset() (*asset, error) {
|
||||||
|
bytes, err := inBTestAssetBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
info := bindataFileInfo{name: "in/b/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
|
||||||
|
a := &asset{bytes: bytes, info: info}
|
||||||
|
return a, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var _inCTestAsset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a"
|
||||||
|
|
||||||
|
func inCTestAssetBytes() ([]byte, error) {
|
||||||
|
return bindataRead(
|
||||||
|
_inCTestAsset,
|
||||||
"in/c/test.asset",
|
"in/c/test.asset",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func inCTestAsset() (*asset, error) {
|
||||||
|
bytes, err := inCTestAssetBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
info := bindataFileInfo{name: "in/c/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
|
||||||
|
a := &asset{bytes: bytes, info: info}
|
||||||
|
return a, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var _inTestAsset = "\x2f\x2f\x20\x73\x61\x6d\x70\x6c\x65\x20\x66\x69\x6c\x65\x0a"
|
||||||
|
|
||||||
|
func inTestAssetBytes() ([]byte, error) {
|
||||||
|
return bindataRead(
|
||||||
|
_inTestAsset,
|
||||||
|
"in/test.asset",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func inTestAsset() (*asset, error) {
|
||||||
|
bytes, err := inTestAssetBytes()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
info := bindataFileInfo{name: "in/test.asset", size: 15, mode: os.FileMode(436), modTime: time.Unix(1445582844, 0)}
|
||||||
|
a := &asset{bytes: bytes, info: info}
|
||||||
|
return a, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Asset loads and returns the asset for the given name.
|
// Asset loads and returns the asset for the given name.
|
||||||
// This returns nil of the asset could not be found.
|
// It returns an error if the asset could not be found or
|
||||||
func Asset(name string) []byte {
|
// could not be loaded.
|
||||||
if f, ok := _bindata[name]; ok {
|
func Asset(name string) ([]byte, error) {
|
||||||
return f()
|
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||||
|
if f, ok := _bindata[cannonicalName]; ok {
|
||||||
|
a, err := f()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
|
||||||
|
}
|
||||||
|
return a.bytes, nil
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("Asset %s not found", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MustAsset is like Asset but panics when Asset would return an error.
|
||||||
|
// It simplifies safe initialization of global variables.
|
||||||
|
func MustAsset(name string) []byte {
|
||||||
|
a, err := Asset(name)
|
||||||
|
if err != nil {
|
||||||
|
panic("asset: Asset(" + name + "): " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
|
// AssetInfo loads and returns the asset info for the given name.
|
||||||
|
// It returns an error if the asset could not be found or
|
||||||
|
// could not be loaded.
|
||||||
|
func AssetInfo(name string) (os.FileInfo, error) {
|
||||||
|
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||||
|
if f, ok := _bindata[cannonicalName]; ok {
|
||||||
|
a, err := f()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
|
||||||
|
}
|
||||||
|
return a.info, nil
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("AssetInfo %s not found", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AssetNames returns the names of the assets.
|
||||||
|
func AssetNames() []string {
|
||||||
|
names := make([]string, 0, len(_bindata))
|
||||||
|
for name := range _bindata {
|
||||||
|
names = append(names, name)
|
||||||
|
}
|
||||||
|
return names
|
||||||
|
}
|
||||||
|
|
||||||
|
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||||
|
var _bindata = map[string]func() (*asset, error){
|
||||||
|
"in/a/test.asset": inATestAsset,
|
||||||
|
"in/b/test.asset": inBTestAsset,
|
||||||
|
"in/c/test.asset": inCTestAsset,
|
||||||
|
"in/test.asset": inTestAsset,
|
||||||
|
}
|
||||||
|
|
||||||
|
// AssetDir returns the file names below a certain
|
||||||
|
// directory embedded in the file by go-bindata.
|
||||||
|
// For example if you run go-bindata on data/... and data contains the
|
||||||
|
// following hierarchy:
|
||||||
|
// data/
|
||||||
|
// foo.txt
|
||||||
|
// img/
|
||||||
|
// a.png
|
||||||
|
// b.png
|
||||||
|
// then AssetDir("data") would return []string{"foo.txt", "img"}
|
||||||
|
// AssetDir("data/img") would return []string{"a.png", "b.png"}
|
||||||
|
// AssetDir("foo.txt") and AssetDir("notexist") would return an error
|
||||||
|
// AssetDir("") will return []string{"data"}.
|
||||||
|
func AssetDir(name string) ([]string, error) {
|
||||||
|
node := _bintree
|
||||||
|
if len(name) != 0 {
|
||||||
|
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||||
|
pathList := strings.Split(cannonicalName, "/")
|
||||||
|
for _, p := range pathList {
|
||||||
|
node = node.Children[p]
|
||||||
|
if node == nil {
|
||||||
|
return nil, fmt.Errorf("Asset %s not found", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if node.Func != nil {
|
||||||
|
return nil, fmt.Errorf("Asset %s not found", name)
|
||||||
|
}
|
||||||
|
rv := make([]string, 0, len(node.Children))
|
||||||
|
for childName := range node.Children {
|
||||||
|
rv = append(rv, childName)
|
||||||
|
}
|
||||||
|
return rv, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type bintree struct {
|
||||||
|
Func func() (*asset, error)
|
||||||
|
Children map[string]*bintree
|
||||||
|
}
|
||||||
|
var _bintree = &bintree{nil, map[string]*bintree{
|
||||||
|
"in": &bintree{nil, map[string]*bintree{
|
||||||
|
"a": &bintree{nil, map[string]*bintree{
|
||||||
|
"test.asset": &bintree{inATestAsset, map[string]*bintree{}},
|
||||||
|
}},
|
||||||
|
"b": &bintree{nil, map[string]*bintree{
|
||||||
|
"test.asset": &bintree{inBTestAsset, map[string]*bintree{}},
|
||||||
|
}},
|
||||||
|
"c": &bintree{nil, map[string]*bintree{
|
||||||
|
"test.asset": &bintree{inCTestAsset, map[string]*bintree{}},
|
||||||
|
}},
|
||||||
|
"test.asset": &bintree{inTestAsset, map[string]*bintree{}},
|
||||||
|
}},
|
||||||
|
}}
|
||||||
|
|
||||||
|
// RestoreAsset restores an asset under the given directory
|
||||||
|
func RestoreAsset(dir, name string) error {
|
||||||
|
data, err := Asset(name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
info, err := AssetInfo(name)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
// RestoreAssets restores an asset under the given directory recursively
|
||||||
var _bindata = map[string]func() []byte{
|
func RestoreAssets(dir, name string) error {
|
||||||
"in/b/test.asset": in_b_test_asset,
|
children, err := AssetDir(name)
|
||||||
"in/test.asset": in_test_asset,
|
// File
|
||||||
"in/a/test.asset": in_a_test_asset,
|
if err != nil {
|
||||||
"in/c/test.asset": in_c_test_asset,
|
return RestoreAsset(dir, name)
|
||||||
|
}
|
||||||
|
// Dir
|
||||||
|
for _, child := range children {
|
||||||
|
err = RestoreAssets(dir, filepath.Join(name, child))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func _filePath(dir, name string) string {
|
||||||
|
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||||
|
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
1
testdata/symlinkFile/file1
vendored
Symbolic link
1
testdata/symlinkFile/file1
vendored
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../symlinkSrc/file1
|
1
testdata/symlinkParent/symlinkTarget
vendored
Symbolic link
1
testdata/symlinkParent/symlinkTarget
vendored
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../symlinkSrc/
|
1
testdata/symlinkRecursiveParent/file1
vendored
Normal file
1
testdata/symlinkRecursiveParent/file1
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
// test file 1
|
1
testdata/symlinkRecursiveParent/symlinkTarget
vendored
Symbolic link
1
testdata/symlinkRecursiveParent/symlinkTarget
vendored
Symbolic link
|
@ -0,0 +1 @@
|
||||||
|
../symlinkRecursiveParent/
|
1
testdata/symlinkSrc/file1
vendored
Normal file
1
testdata/symlinkSrc/file1
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
// symlink file 1
|
1
testdata/symlinkSrc/file2
vendored
Normal file
1
testdata/symlinkSrc/file2
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
// symlink file 2
|
1
testdata/symlinkSrc/file3
vendored
Normal file
1
testdata/symlinkSrc/file3
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
// symlink file 3
|
1
testdata/symlinkSrc/file4
vendored
Normal file
1
testdata/symlinkSrc/file4
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
// symlink file 4
|
191
toc.go
191
toc.go
|
@ -7,8 +7,139 @@ package bindata
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type assetTree struct {
|
||||||
|
Asset Asset
|
||||||
|
Children map[string]*assetTree
|
||||||
|
}
|
||||||
|
|
||||||
|
func newAssetTree() *assetTree {
|
||||||
|
tree := &assetTree{}
|
||||||
|
tree.Children = make(map[string]*assetTree)
|
||||||
|
return tree
|
||||||
|
}
|
||||||
|
|
||||||
|
func (node *assetTree) child(name string) *assetTree {
|
||||||
|
rv, ok := node.Children[name]
|
||||||
|
if !ok {
|
||||||
|
rv = newAssetTree()
|
||||||
|
node.Children[name] = rv
|
||||||
|
}
|
||||||
|
return rv
|
||||||
|
}
|
||||||
|
|
||||||
|
func (root *assetTree) Add(route []string, asset Asset) {
|
||||||
|
for _, name := range route {
|
||||||
|
root = root.child(name)
|
||||||
|
}
|
||||||
|
root.Asset = asset
|
||||||
|
}
|
||||||
|
|
||||||
|
func ident(w io.Writer, n int) {
|
||||||
|
for i := 0; i < n; i++ {
|
||||||
|
w.Write([]byte{'\t'})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (root *assetTree) funcOrNil() string {
|
||||||
|
if root.Asset.Func == "" {
|
||||||
|
return "nil"
|
||||||
|
} else {
|
||||||
|
return root.Asset.Func
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (root *assetTree) writeGoMap(w io.Writer, nident int) {
|
||||||
|
fmt.Fprintf(w, "&bintree{%s, map[string]*bintree{", root.funcOrNil())
|
||||||
|
|
||||||
|
if len(root.Children) > 0 {
|
||||||
|
io.WriteString(w, "\n")
|
||||||
|
|
||||||
|
// Sort to make output stable between invocations
|
||||||
|
filenames := make([]string, len(root.Children))
|
||||||
|
i := 0
|
||||||
|
for filename, _ := range root.Children {
|
||||||
|
filenames[i] = filename
|
||||||
|
i++
|
||||||
|
}
|
||||||
|
sort.Strings(filenames)
|
||||||
|
|
||||||
|
for _, p := range filenames {
|
||||||
|
ident(w, nident+1)
|
||||||
|
fmt.Fprintf(w, `"%s": `, p)
|
||||||
|
root.Children[p].writeGoMap(w, nident+1)
|
||||||
|
}
|
||||||
|
ident(w, nident)
|
||||||
|
}
|
||||||
|
|
||||||
|
io.WriteString(w, "}}")
|
||||||
|
if nident > 0 {
|
||||||
|
io.WriteString(w, ",")
|
||||||
|
}
|
||||||
|
io.WriteString(w, "\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (root *assetTree) WriteAsGoMap(w io.Writer) error {
|
||||||
|
_, err := fmt.Fprint(w, `type bintree struct {
|
||||||
|
Func func() (*asset, error)
|
||||||
|
Children map[string]*bintree
|
||||||
|
}
|
||||||
|
var _bintree = `)
|
||||||
|
root.writeGoMap(w, 0)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func writeTOCTree(w io.Writer, toc []Asset) error {
|
||||||
|
_, err := fmt.Fprintf(w, `// AssetDir returns the file names below a certain
|
||||||
|
// directory embedded in the file by go-bindata.
|
||||||
|
// For example if you run go-bindata on data/... and data contains the
|
||||||
|
// following hierarchy:
|
||||||
|
// data/
|
||||||
|
// foo.txt
|
||||||
|
// img/
|
||||||
|
// a.png
|
||||||
|
// b.png
|
||||||
|
// then AssetDir("data") would return []string{"foo.txt", "img"}
|
||||||
|
// AssetDir("data/img") would return []string{"a.png", "b.png"}
|
||||||
|
// AssetDir("foo.txt") and AssetDir("notexist") would return an error
|
||||||
|
// AssetDir("") will return []string{"data"}.
|
||||||
|
func AssetDir(name string) ([]string, error) {
|
||||||
|
node := _bintree
|
||||||
|
if len(name) != 0 {
|
||||||
|
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||||
|
pathList := strings.Split(cannonicalName, "/")
|
||||||
|
for _, p := range pathList {
|
||||||
|
node = node.Children[p]
|
||||||
|
if node == nil {
|
||||||
|
return nil, fmt.Errorf("Asset %%s not found", name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if node.Func != nil {
|
||||||
|
return nil, fmt.Errorf("Asset %%s not found", name)
|
||||||
|
}
|
||||||
|
rv := make([]string, 0, len(node.Children))
|
||||||
|
for childName := range node.Children {
|
||||||
|
rv = append(rv, childName)
|
||||||
|
}
|
||||||
|
return rv, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
`)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
tree := newAssetTree()
|
||||||
|
for i := range toc {
|
||||||
|
pathList := strings.Split(toc[i].Name, "/")
|
||||||
|
tree.Add(pathList, toc[i])
|
||||||
|
}
|
||||||
|
return tree.WriteAsGoMap(w)
|
||||||
|
}
|
||||||
|
|
||||||
// writeTOC writes the table of contents file.
|
// writeTOC writes the table of contents file.
|
||||||
func writeTOC(w io.Writer, toc []Asset) error {
|
func writeTOC(w io.Writer, toc []Asset) error {
|
||||||
err := writeTOCHeader(w)
|
err := writeTOCHeader(w)
|
||||||
|
@ -28,18 +159,58 @@ func writeTOC(w io.Writer, toc []Asset) error {
|
||||||
|
|
||||||
// writeTOCHeader writes the table of contents file header.
|
// writeTOCHeader writes the table of contents file header.
|
||||||
func writeTOCHeader(w io.Writer) error {
|
func writeTOCHeader(w io.Writer) error {
|
||||||
_, err := fmt.Fprintf(w, `
|
_, err := fmt.Fprintf(w, `// Asset loads and returns the asset for the given name.
|
||||||
// Asset loads and returns the asset for the given name.
|
// It returns an error if the asset could not be found or
|
||||||
// This returns nil of the asset could not be found.
|
// could not be loaded.
|
||||||
func Asset(name string) []byte {
|
func Asset(name string) ([]byte, error) {
|
||||||
if f, ok := _bindata[name]; ok {
|
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||||
return f()
|
if f, ok := _bindata[cannonicalName]; ok {
|
||||||
|
a, err := f()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("Asset %%s can't read by error: %%v", name, err)
|
||||||
}
|
}
|
||||||
return nil
|
return a.bytes, nil
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("Asset %%s not found", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MustAsset is like Asset but panics when Asset would return an error.
|
||||||
|
// It simplifies safe initialization of global variables.
|
||||||
|
func MustAsset(name string) []byte {
|
||||||
|
a, err := Asset(name)
|
||||||
|
if err != nil {
|
||||||
|
panic("asset: Asset(" + name + "): " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
|
||||||
|
// AssetInfo loads and returns the asset info for the given name.
|
||||||
|
// It returns an error if the asset could not be found or
|
||||||
|
// could not be loaded.
|
||||||
|
func AssetInfo(name string) (os.FileInfo, error) {
|
||||||
|
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||||
|
if f, ok := _bindata[cannonicalName]; ok {
|
||||||
|
a, err := f()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("AssetInfo %%s can't read by error: %%v", name, err)
|
||||||
|
}
|
||||||
|
return a.info, nil
|
||||||
|
}
|
||||||
|
return nil, fmt.Errorf("AssetInfo %%s not found", name)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AssetNames returns the names of the assets.
|
||||||
|
func AssetNames() []string {
|
||||||
|
names := make([]string, 0, len(_bindata))
|
||||||
|
for name := range _bindata {
|
||||||
|
names = append(names, name)
|
||||||
|
}
|
||||||
|
return names
|
||||||
}
|
}
|
||||||
|
|
||||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||||
var _bindata = map[string] func() []byte {
|
var _bindata = map[string]func() (*asset, error){
|
||||||
`)
|
`)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -52,8 +223,8 @@ func writeTOCAsset(w io.Writer, asset *Asset) error {
|
||||||
|
|
||||||
// writeTOCFooter writes the table of contents file footer.
|
// writeTOCFooter writes the table of contents file footer.
|
||||||
func writeTOCFooter(w io.Writer) error {
|
func writeTOCFooter(w io.Writer) error {
|
||||||
_, err := fmt.Fprintf(w, `
|
_, err := fmt.Fprintf(w, `}
|
||||||
}
|
|
||||||
`)
|
`)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user