2013-10-30 01:11:04 +00:00
|
|
|
// 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"
|
|
|
|
)
|
|
|
|
|
2013-10-30 12:14:58 +00:00
|
|
|
// writeDebug writes the debug code file.
|
2013-10-30 13:45:04 +00:00
|
|
|
func writeDebug(w io.Writer, toc []Asset) error {
|
|
|
|
err := writeDebugHeader(w)
|
2013-10-30 12:14:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
for i := range toc {
|
2013-10-30 13:45:04 +00:00
|
|
|
err = writeDebugAsset(w, &toc[i])
|
2013-10-30 12:14:58 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2013-10-30 01:16:14 +00:00
|
|
|
// writeDebugHeader writes output file headers.
|
2013-10-30 01:11:04 +00:00
|
|
|
// This targets debug builds.
|
2013-10-30 13:45:04 +00:00
|
|
|
func writeDebugHeader(w io.Writer) error {
|
|
|
|
_, err := fmt.Fprintf(w, `import (
|
2013-11-08 15:38:45 +00:00
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
2014-05-16 17:34:04 +00:00
|
|
|
"strings"
|
2013-10-30 01:11:04 +00:00
|
|
|
)
|
|
|
|
|
2014-03-07 21:13:34 +00:00
|
|
|
// bindata_read reads the given file from disk. It returns an error on failure.
|
2013-11-08 15:38:45 +00:00
|
|
|
func bindata_read(path, name string) ([]byte, error) {
|
|
|
|
buf, err := ioutil.ReadFile(path)
|
2013-10-30 01:11:04 +00:00
|
|
|
if err != nil {
|
2013-11-08 15:38:45 +00:00
|
|
|
err = fmt.Errorf("Error reading asset %%s at %%s: %%v", name, path, err)
|
2013-10-30 01:11:04 +00:00
|
|
|
}
|
2013-11-08 15:38:45 +00:00
|
|
|
return buf, err
|
2013-10-30 01:11:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
`)
|
2013-10-30 12:14:58 +00:00
|
|
|
return err
|
2013-10-30 01:11:04 +00:00
|
|
|
}
|
|
|
|
|
2013-10-30 12:14:58 +00:00
|
|
|
// writeDebugAsset write a debug entry for the given asset.
|
2013-10-30 01:11:04 +00:00
|
|
|
// A debug entry is simply a function which reads the asset from
|
|
|
|
// the original file (e.g.: from disk).
|
2013-10-30 13:45:04 +00:00
|
|
|
func writeDebugAsset(w io.Writer, asset *Asset) error {
|
2014-05-28 12:43:02 +00:00
|
|
|
_, err := fmt.Fprintf(w, `// %s reads file data from disk. It returns an error on failure.
|
2013-11-08 15:38:45 +00:00
|
|
|
func %s() ([]byte, error) {
|
2013-10-30 01:11:04 +00:00
|
|
|
return bindata_read(
|
|
|
|
%q,
|
|
|
|
%q,
|
|
|
|
)
|
|
|
|
}
|
2014-05-28 12:43:02 +00:00
|
|
|
|
2013-10-30 13:45:04 +00:00
|
|
|
`, asset.Func, asset.Func, asset.Path, asset.Name)
|
2013-10-30 12:14:58 +00:00
|
|
|
return err
|
2013-10-30 01:11:04 +00:00
|
|
|
}
|