├── .travis.yml ├── gen.go ├── writer.go ├── LICENSE ├── cmd └── go-bincode │ └── main.go ├── bindata.go ├── tests ├── bincoder_test.go ├── bincoder.go └── bincode.go ├── README.md └── template.go /.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | go: 3 | - 1.5 4 | - 1.4.2 5 | - release 6 | - tip 7 | script: 8 | - go test -v ./... 9 | -------------------------------------------------------------------------------- /gen.go: -------------------------------------------------------------------------------- 1 | //go:generate go run cmd/go-bincode/main.go -pkg bincode -ignore tests -output-dir tests 2 | package bincode 3 | 4 | import "path/filepath" 5 | 6 | func Generate(root, pkg, outputDir string, ignores []string) error { 7 | // generate code archive 8 | err := bindata{ 9 | root: ".", 10 | pkg: pkg, 11 | outputDir: outputDir, 12 | ignores: ignores, 13 | }.exec() 14 | if err != nil { 15 | return err 16 | } 17 | 18 | // generate bincoder 19 | return writeToFile( 20 | filepath.Join(outputDir, "bincoder.go"), 21 | codeTemplates.toString(), 22 | binCode{Package: pkg}, 23 | ) 24 | } 25 | -------------------------------------------------------------------------------- /writer.go: -------------------------------------------------------------------------------- 1 | package bincode 2 | 3 | import ( 4 | "bufio" 5 | "bytes" 6 | "io" 7 | "os" 8 | tmpl "text/template" 9 | 10 | "golang.org/x/tools/imports" 11 | ) 12 | 13 | func writeToFile(file, template string, binCode binCode) error { 14 | f, err := os.Create(file) 15 | if err != nil { 16 | return err 17 | } 18 | defer f.Close() 19 | 20 | w := bufio.NewWriter(f) 21 | defer w.Flush() 22 | 23 | b, err := writeWithFormat(file, template, binCode) 24 | if err != nil { 25 | return err 26 | } 27 | 28 | w.Write(b) 29 | return nil 30 | } 31 | 32 | func writeWithFormat(file, template string, binCode binCode) ([]byte, error) { 33 | var b bytes.Buffer 34 | w := bufio.NewWriter(&b) 35 | 36 | write(w, template, binCode) 37 | w.Flush() 38 | 39 | formatted, err := imports.Process(file, b.Bytes(), nil) 40 | if err != nil { 41 | return nil, err 42 | } 43 | return formatted, nil 44 | } 45 | 46 | func write(w io.Writer, tplText string, binCode binCode) error { 47 | tpl := tmpl.Must(tmpl.New("t").Parse(tplText)) 48 | if err := tpl.Execute(w, binCode); err != nil { 49 | return err 50 | } 51 | 52 | return nil 53 | } 54 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) [2015] [go-bincode] 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /cmd/go-bincode/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "os" 7 | "strings" 8 | 9 | "github.com/monochromegane/go-bincode" 10 | ) 11 | 12 | var pkg string 13 | var outputDir string 14 | var ignores []string 15 | 16 | func init() { 17 | flag.StringVar(&pkg, "pkg", "main", "Package name to use in the generated code.") 18 | flag.StringVar(&outputDir, "output-dir", ".", "Output directory") 19 | flag.Var((*AppendSliceValue)(&ignores), "ignore", "Regex pattern to ignore") 20 | flag.Parse() 21 | } 22 | func main() { 23 | err := bincode.Generate(".", pkg, outputDir, ignores) 24 | if err != nil { 25 | fmt.Fprintf(os.Stderr, "%v\n", err) 26 | os.Exit(1) 27 | } 28 | } 29 | 30 | // borrowed from https://github.com/jteeuwen/go-bindata/blob/master/go-bindata/AppendSliceValue.go 31 | // (re-borrowed from https://github.com/hashicorp/serf/blob/master/command/agent/flag_slice_value.go) 32 | 33 | // AppendSliceValue implements the flag.Value interface and allows multiple 34 | // calls to the same variable to append a list. 35 | type AppendSliceValue []string 36 | 37 | func (s *AppendSliceValue) String() string { 38 | return strings.Join(*s, ",") 39 | } 40 | 41 | func (s *AppendSliceValue) Set(value string) error { 42 | if *s == nil { 43 | *s = make([]string, 0, 1) 44 | } 45 | 46 | *s = append(*s, value) 47 | return nil 48 | } 49 | -------------------------------------------------------------------------------- /bindata.go: -------------------------------------------------------------------------------- 1 | package bincode 2 | 3 | import ( 4 | "os" 5 | "os/exec" 6 | "path/filepath" 7 | "strings" 8 | ) 9 | 10 | type bindata struct { 11 | root string 12 | pkg string 13 | outputDir string 14 | ignores []string 15 | } 16 | 17 | func (b bindata) exec() error { 18 | files, err := b.gofiles() 19 | if err != nil { 20 | return err 21 | } 22 | 23 | args := []string{"-o", filepath.Join(b.outputDir, "bincode.go"), "-pkg", b.pkg} 24 | 25 | if len(b.ignores) > 0 { 26 | for _, i := range b.ignores { 27 | args = append(args, "-ignore", i) 28 | } 29 | } 30 | 31 | args = append(args, files...) 32 | return exec.Command("go-bindata", args...).Run() 33 | } 34 | 35 | func (b bindata) gofiles() ([]string, error) { 36 | var files []string 37 | err := filepath.Walk(b.root, func(path string, info os.FileInfo, err error) error { 38 | if info.IsDir() { 39 | name := info.Name() 40 | // Skip hidden directory 41 | if strings.HasPrefix(name, ".") && len(name) > 1 { 42 | return filepath.SkipDir 43 | } 44 | return nil 45 | } 46 | 47 | // Only .go file 48 | if !strings.HasSuffix(info.Name(), ".go") { 49 | return nil 50 | } 51 | 52 | // Exclude generated code 53 | if info.Name() == "bincode.go" || info.Name() == "bincoder.go" { 54 | return nil 55 | } 56 | 57 | files = append(files, path) 58 | return nil 59 | }) 60 | if err != nil { 61 | return nil, err 62 | } 63 | 64 | return files, nil 65 | } 66 | -------------------------------------------------------------------------------- /tests/bincoder_test.go: -------------------------------------------------------------------------------- 1 | package bincode 2 | 3 | import ( 4 | "bytes" 5 | "fmt" 6 | "io/ioutil" 7 | "path/filepath" 8 | "strings" 9 | "testing" 10 | ) 11 | 12 | func TestListCode(t *testing.T) { 13 | buf := &bytes.Buffer{} 14 | binCoder{buf}.listCode() 15 | 16 | actual := buf.String() 17 | expects := []string{ 18 | "bindata.go", 19 | "cmd/go-bincode/main.go", 20 | "gen.go", 21 | "template.go", 22 | "writer.go", 23 | } 24 | 25 | for _, e := range expects { 26 | if !strings.Contains(actual, e) { 27 | t.Errorf("code list should contain %s, but not contains", e) 28 | } 29 | } 30 | } 31 | 32 | func TestListCode_Exclude(t *testing.T) { 33 | buf := &bytes.Buffer{} 34 | binCoder{buf}.listCode() 35 | 36 | actual := buf.String() 37 | excludes := []string{ 38 | "bincode.go", 39 | "bincoder.go", 40 | ".git", 41 | } 42 | 43 | for _, e := range excludes { 44 | if strings.Contains(actual, e) { 45 | t.Errorf("code list should not contain %s, but contains", e) 46 | } 47 | } 48 | } 49 | 50 | func TestShowCode(t *testing.T) { 51 | buf := &bytes.Buffer{} 52 | binCoder{buf}.listCode() 53 | 54 | list := strings.Split(buf.String(), "\n") 55 | 56 | for _, c := range list { 57 | if c == "" { 58 | continue 59 | } 60 | expect := &bytes.Buffer{} 61 | binCoder{expect}.showCode(c) 62 | 63 | actual, err := ioutil.ReadFile(filepath.Join("..", c)) 64 | if err != nil { 65 | fmt.Printf("%v\n", err) 66 | } 67 | if expect.String() != string(actual)+"\n" { 68 | t.Errorf("code should equal %s but not equal", filepath.Join("..", c)) 69 | } 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # go-bincode [![Build Status](https://travis-ci.org/monochromegane/go-bincode.svg?branch=master)](https://travis-ci.org/monochromegane/go-bincode) 2 | 3 | A tool for embedding Go code in a Go binary using go-bindata. 4 | 5 | ![go-bincode](https://cloud.githubusercontent.com/assets/1845486/9424618/4ada7c6a-492d-11e5-9958-73bc329ac35c.gif) 6 | 7 | ## Usage 8 | 9 | 1. Install go-bindata and go-bincode. 10 | 2. Execute `go-bincode` command at your repository. 11 | 12 | ```sh 13 | $ go-bincode 14 | ``` 15 | 16 | You can find `bincode.go` and `bincoder.go`. 17 | So, your Go program get {show,list,restore}-code options. 18 | 19 | ### List code 20 | 21 | `list-code` list your code. 22 | 23 | ```sh 24 | $ my-app -list-code 25 | app.go 26 | my-app/main.go 27 | ``` 28 | **Note** code-list don't contain `bincode.go` and `bincoder.go`. 29 | 30 | ### Show code 31 | 32 | `show-code` show your code. 33 | 34 | ```sh 35 | $ my-app -show-code my-app/main.go 36 | package main 37 | 38 | func main() { 39 | my-app.Do() 40 | } 41 | ``` 42 | 43 | ### Restore code 44 | 45 | `restore-code` restore your code. 46 | 47 | ```sh 48 | $ my-app -restore-code 49 | ``` 50 | 51 | ## Generated code dependency 52 | 53 | Generated code (`bincode.go` and `bincoder.go`) don't depends on your code, only provides {show,list,restore}-code options at init() function. 54 | 55 | ## Installation 56 | 57 | ```sh 58 | $ go get -u github.com/jteeuwen/go-bindata/... # Requirement 59 | $ go get -u github.com/monochromegane/go-bincode/... 60 | ``` 61 | 62 | ## Contribution 63 | 64 | 1. Fork it 65 | 2. Create a feature branch 66 | 3. Commit your changes 67 | 4. Rebase your local changes against the master branch 68 | 5. Run test suite with the `go generate && go test ./...` command and confirm that it passes 69 | 6. Run `gofmt -s` 70 | 7. Create new Pull Request 71 | 72 | ## License 73 | 74 | [MIT](https://github.com/monochromegane/go-bincode/blob/master/LICENSE) 75 | 76 | ## Author 77 | 78 | [monochromegane](https://github.com/monochromegane) 79 | 80 | -------------------------------------------------------------------------------- /tests/bincoder.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-bincode. 2 | // DO NOT EDIT! 3 | package bincode 4 | 5 | import ( 6 | "bytes" 7 | "flag" 8 | "fmt" 9 | "io" 10 | "io/ioutil" 11 | "os" 12 | "path/filepath" 13 | "strings" 14 | ) 15 | 16 | func init() { 17 | var code string 18 | var list bool 19 | var restore bool 20 | 21 | f := flag.NewFlagSet(os.Args[0], flag.ContinueOnError) 22 | 23 | f.StringVar(&code, "show-code", "", "show source code") 24 | f.BoolVar(&list, "list-code", false, "list source code") 25 | f.BoolVar(&restore, "restore-code", false, "restore source code") 26 | 27 | buf := &bytes.Buffer{} 28 | f.SetOutput(buf) 29 | 30 | err := f.Parse(os.Args[1:]) 31 | if err != nil { 32 | // Continue if flag not found 33 | if strings.Contains(err.Error(), "flag provided but not defined:") { 34 | return 35 | } 36 | // Continue if flag is "h" or "help" 37 | if err == flag.ErrHelp { 38 | fmt.Fprintln(os.Stderr, buf.String()) 39 | return 40 | } 41 | // Exit if flag has error 42 | fmt.Fprintln(os.Stderr, buf.String()) 43 | os.Exit(2) 44 | } 45 | 46 | if list { 47 | newBinCoder().listCode() 48 | os.Exit(0) 49 | } 50 | 51 | if code != "" { 52 | err := newBinCoder().showCode(code) 53 | if err != nil { 54 | fmt.Fprintln(os.Stderr, err) 55 | os.Exit(1) 56 | } 57 | os.Exit(0) 58 | } 59 | 60 | if restore { 61 | newBinCoder().restoreCode() 62 | if err != nil { 63 | fmt.Fprintln(os.Stderr, err) 64 | os.Exit(1) 65 | } 66 | os.Exit(0) 67 | } 68 | } 69 | 70 | type binCoder struct { 71 | writer io.Writer 72 | } 73 | 74 | func newBinCoder() *binCoder { 75 | return &binCoder{writer: os.Stdout} 76 | } 77 | 78 | func (b binCoder) listCode() { 79 | for _, a := range AssetNames() { 80 | b.out(a) 81 | } 82 | } 83 | 84 | func (b binCoder) showCode(name string) error { 85 | asset, err := Asset(name) 86 | if err != nil { 87 | return err 88 | } 89 | b.out(string(asset)) 90 | return nil 91 | } 92 | 93 | func (b binCoder) restoreCode() error { 94 | for _, name := range AssetNames() { 95 | // mkdir 96 | if err := os.MkdirAll(filepath.Dir(name), 0755); err != nil { 97 | return err 98 | } 99 | // write file 100 | asset, err := Asset(name) 101 | if err != nil { 102 | return err 103 | } 104 | err = ioutil.WriteFile(name, asset, 0644) 105 | if err != nil { 106 | return err 107 | } 108 | } 109 | return nil 110 | } 111 | 112 | func (b binCoder) out(s string) { 113 | fmt.Fprintln(b.writer, s) 114 | } 115 | -------------------------------------------------------------------------------- /template.go: -------------------------------------------------------------------------------- 1 | package bincode 2 | 3 | type binCode struct { 4 | Package string 5 | } 6 | 7 | type templates []*template 8 | 9 | func (ts templates) toString() string { 10 | var template string 11 | for _, t := range ts { 12 | template = template + t.text 13 | } 14 | return template 15 | } 16 | 17 | var codeTemplates = templates{ 18 | packageTpl, 19 | importTpl, 20 | initTpl, 21 | binCoderTpl, 22 | } 23 | 24 | type template struct { 25 | name string 26 | text string 27 | } 28 | 29 | var packageTpl = &template{ 30 | name: "package", 31 | text: `// Code generated by go-bincode. 32 | // DO NOT EDIT! 33 | package {{ .Package }} 34 | `} 35 | 36 | var importTpl = &template{ 37 | name: "import", 38 | text: ` 39 | import ( 40 | "bytes" 41 | "flag" 42 | "fmt" 43 | "io/ioutil" 44 | "os" 45 | "path/filepath" 46 | "strings" 47 | ) 48 | `} 49 | 50 | var initTpl = &template{ 51 | name: "init", 52 | text: ` 53 | func init() { 54 | var code string 55 | var list bool 56 | var restore bool 57 | 58 | f := flag.NewFlagSet(os.Args[0], flag.ContinueOnError) 59 | 60 | f.StringVar(&code, "show-code", "", "show source code") 61 | f.BoolVar(&list, "list-code", false, "list source code") 62 | f.BoolVar(&restore, "restore-code", false, "restore source code") 63 | 64 | buf := &bytes.Buffer{} 65 | f.SetOutput(buf) 66 | 67 | err := f.Parse(os.Args[1:]) 68 | if err != nil { 69 | // Continue if flag not found 70 | if strings.Contains(err.Error(), "flag provided but not defined:") { 71 | return 72 | } 73 | // Continue if flag is "h" or "help" 74 | if err == flag.ErrHelp { 75 | fmt.Fprintln(os.Stderr, buf.String()) 76 | return 77 | } 78 | // Exit if flag has error 79 | fmt.Fprintln(os.Stderr, buf.String()) 80 | os.Exit(2) 81 | } 82 | 83 | if list { 84 | newBinCoder().listCode() 85 | os.Exit(0) 86 | } 87 | 88 | if code != "" { 89 | err := newBinCoder().showCode(code) 90 | if err != nil { 91 | fmt.Fprintln(os.Stderr, err) 92 | os.Exit(1) 93 | } 94 | os.Exit(0) 95 | } 96 | 97 | if restore { 98 | newBinCoder().restoreCode() 99 | if err != nil { 100 | fmt.Fprintln(os.Stderr, err) 101 | os.Exit(1) 102 | } 103 | os.Exit(0) 104 | } 105 | } 106 | `} 107 | 108 | var binCoderTpl = &template{ 109 | name: "binCoder", 110 | text: ` 111 | type binCoder struct { 112 | writer io.Writer 113 | } 114 | 115 | func newBinCoder() *binCoder { 116 | return &binCoder{writer: os.Stdout} 117 | } 118 | 119 | func (b binCoder) listCode() { 120 | for _, a := range AssetNames() { 121 | b.out(a) 122 | } 123 | } 124 | 125 | func (b binCoder) showCode(name string) error { 126 | asset, err := Asset(name) 127 | if err != nil { 128 | return err 129 | } 130 | b.out(string(asset)) 131 | return nil 132 | } 133 | 134 | func (b binCoder) restoreCode() error { 135 | for _, name := range AssetNames() { 136 | // mkdir 137 | if err := os.MkdirAll(filepath.Dir(name), 0755); err != nil { 138 | return err 139 | } 140 | // write file 141 | asset, err := Asset(name) 142 | if err != nil { 143 | return err 144 | } 145 | err = ioutil.WriteFile(name, asset, 0644) 146 | if err != nil { 147 | return err 148 | } 149 | } 150 | return nil 151 | } 152 | 153 | func (b binCoder) out(s string) { 154 | fmt.Fprintln(b.writer, s) 155 | } 156 | `} 157 | -------------------------------------------------------------------------------- /tests/bincode.go: -------------------------------------------------------------------------------- 1 | // Code generated by go-bindata. 2 | // sources: 3 | // bindata.go 4 | // cmd/go-bincode/main.go 5 | // gen.go 6 | // template.go 7 | // writer.go 8 | // DO NOT EDIT! 9 | 10 | package bincode 11 | 12 | import ( 13 | "bytes" 14 | "compress/gzip" 15 | "fmt" 16 | "io" 17 | "strings" 18 | "os" 19 | "time" 20 | "io/ioutil" 21 | "path/filepath" 22 | ) 23 | 24 | func bindataRead(data []byte, name string) ([]byte, error) { 25 | gz, err := gzip.NewReader(bytes.NewBuffer(data)) 26 | if err != nil { 27 | return nil, fmt.Errorf("Read %q: %v", name, err) 28 | } 29 | 30 | var buf bytes.Buffer 31 | _, err = io.Copy(&buf, gz) 32 | clErr := gz.Close() 33 | 34 | if err != nil { 35 | return nil, fmt.Errorf("Read %q: %v", name, err) 36 | } 37 | if clErr != nil { 38 | return nil, err 39 | } 40 | 41 | return buf.Bytes(), nil 42 | } 43 | 44 | type asset struct { 45 | bytes []byte 46 | info os.FileInfo 47 | } 48 | 49 | type bindataFileInfo struct { 50 | name string 51 | size int64 52 | mode os.FileMode 53 | modTime time.Time 54 | } 55 | 56 | func (fi bindataFileInfo) Name() string { 57 | return fi.name 58 | } 59 | func (fi bindataFileInfo) Size() int64 { 60 | return fi.size 61 | } 62 | func (fi bindataFileInfo) Mode() os.FileMode { 63 | return fi.mode 64 | } 65 | func (fi bindataFileInfo) ModTime() time.Time { 66 | return fi.modTime 67 | } 68 | func (fi bindataFileInfo) IsDir() bool { 69 | return false 70 | } 71 | func (fi bindataFileInfo) Sys() interface{} { 72 | return nil 73 | } 74 | 75 | var _bindataGo = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\x7c\x53\x4d\x6f\xdb\x30\x0c\x3d\x5b\xbf\x82\xf5\xa1\x90\x01\x47\xd9\xae\x03\xb2\xcb\x3e\xb0\xee\xb0\x0d\xeb\x61\x87\x61\x18\x64\x5b\x76\x85\x38\x92\x20\xcb\x43\x82\x36\xff\x7d\xa4\xe4\x8f\x64\x68\xd7\x43\x63\x91\xd4\x7b\x8f\x8f\x94\x93\xf5\x5e\x76\x0a\x2a\x6d\x6a\xdb\x28\xc6\xf4\xc1\x59\x1f\x80\xb3\x2c\xb7\x43\x1e\xff\x6f\xd5\x51\xd5\xf4\xe9\x64\x78\xd8\xb6\xba\x57\xf4\x41\x81\x21\x78\x6d\x3a\x2c\x2b\x18\x0b\x27\x17\x61\x1a\x19\x24\x60\x62\xac\x03\x3c\xb2\xcc\x5b\x1b\x20\xfe\xa5\x62\x96\xb9\x7d\x07\xd7\x11\x3b\x06\x37\x86\xf7\xda\x2f\x11\xdd\x19\xeb\xd5\x80\x35\x3f\x7f\x4d\xb1\x33\x63\xed\x68\x6a\xe0\xd5\xcc\x52\x00\x09\xe3\xf8\xe3\xbd\xf5\x44\x46\xda\x86\x92\xce\xf0\x66\x07\x95\xe8\x6c\x8c\xf0\x02\x11\xdb\x18\xbe\xd9\x81\xd1\x3d\xd5\x66\x5e\x85\xd1\x1b\x8a\xb2\x0c\xc1\x33\xe9\xbb\x81\xae\xcd\x8c\x8f\xf9\xc6\xe6\x25\xcc\xfd\x8a\xcf\x56\x1b\x5e\x89\x45\x6c\x09\xf9\xe4\x1a\xf2\xe4\x05\x1e\x37\xd8\x1a\xde\xa8\x04\xfe\x12\x22\x72\xf6\x8a\xee\x4c\xed\x14\xf0\x16\x5e\x45\xee\x16\xf5\xfe\x2e\x41\x13\x9f\x97\x86\x06\x30\x17\xc5\x7c\x12\xb3\x03\xe9\x9c\x32\x0d\xa7\x13\xe1\xa7\x12\xa4\xd0\xd8\x11\x8a\x5e\x75\xff\x53\x1a\xdb\x16\x42\x60\xd9\xdc\x26\x5a\x25\xde\xd9\xc3\x41\x62\x51\xde\xd9\xcd\x64\x22\x82\xd1\x15\xaa\x15\xdf\x47\x83\x56\x3d\x67\xf4\x62\x24\xf0\xd9\x9e\x32\xd9\x5e\x90\xde\x3f\xd2\x27\xca\x75\x5c\xd9\x34\x84\xc5\xbe\x1f\xb2\xdf\xa3\x15\xb4\x0f\xa8\x0f\x09\x38\x85\x61\x06\xd3\xa6\xb5\x60\x07\xf1\x11\xeb\xef\xf0\x3b\x4d\x71\xa2\x58\x06\x4c\x96\x52\xa5\xb8\x1b\x70\x02\xbc\x48\x66\x19\x79\x50\xc4\x15\x33\x5f\xf0\x40\x03\xcf\xb2\xed\x16\xee\xf7\xda\xc1\x83\x6e\x1a\x65\xa0\xd1\x5e\xd5\xc1\xfa\x13\xe5\x10\x67\x5a\x5e\xf1\x49\x0e\xdf\xbc\x6a\xf5\x91\x13\x0e\xda\x2c\xf2\x02\x6e\x6f\xe3\xe8\x28\x42\x53\x7b\x9d\x88\x66\x33\x97\xa6\x08\x1f\x85\x50\xee\xcc\xd6\x3c\xae\x58\x9c\x0f\x8b\x22\xbe\x9a\xfe\x04\xb8\x23\xf1\x5a\xea\xe1\xe6\x82\xfc\x7e\x6c\x89\xfc\x42\x3c\x69\xa0\x95\x4a\xa4\xcf\x62\x7e\x38\xd6\xfd\xd8\x28\xe8\x94\x51\x5e\x06\xd5\x40\x7c\xbe\xab\x41\x09\x09\x76\xbb\xab\x2d\x85\xa7\xa7\x97\xd2\x3e\xe6\x5f\x60\x4c\xc3\x5d\x96\x6c\x7a\x67\x64\x41\xc1\xae\xeb\xcf\xff\x7b\x6b\x78\x2c\xd7\x07\x77\x61\x26\x82\xd1\xed\x33\xfb\x1b\x00\x00\xff\xff\xe6\xcd\x11\x5e\x90\x04\x00\x00") 76 | 77 | func bindataGoBytes() ([]byte, error) { 78 | return bindataRead( 79 | _bindataGo, 80 | "bindata.go", 81 | ) 82 | } 83 | 84 | func bindataGo() (*asset, error) { 85 | bytes, err := bindataGoBytes() 86 | if err != nil { 87 | return nil, err 88 | } 89 | 90 | info := bindataFileInfo{name: "bindata.go", size: 1168, mode: os.FileMode(420), modTime: time.Unix(1440241348, 0)} 91 | a := &asset{bytes: bytes, info: info} 92 | return a, nil 93 | } 94 | 95 | var _cmdGoBincodeMainGo = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\x84\x53\x4d\x6b\xdc\x30\x10\x3d\xaf\x7e\xc5\xd4\xd0\x20\x87\x8d\xdd\x5e\x03\x39\x14\xfa\x01\xbd\x34\x34\x90\x4b\x5b\x82\x6c\x8f\x6d\x35\xb6\x64\xa4\x71\x3e\x28\xf9\xef\x9d\x91\xbd\xdb\xed\x2e\xb4\x17\x4b\x9a\xd9\x79\x33\xef\xcd\xdb\xc9\xd4\xf7\xa6\x43\x18\x8d\x75\x4a\xd9\x71\xf2\x81\x40\xab\x4d\xd6\x0e\xa6\xcb\xe4\x1c\x49\x0e\x1f\xe5\x1b\x29\x58\xd7\xf1\x95\xef\x9d\xa5\x7e\xae\x8a\xda\x8f\xe5\xe8\x9d\xaf\xfb\xe0\x47\xec\x8c\xc3\xb2\xf3\x17\x95\x75\xb5\x6f\x30\x53\xb9\x52\x0f\x26\xc0\x74\xdf\xc1\x52\x9c\x9e\x7e\xa6\x69\xa6\xf7\x36\x1c\x06\x6d\xe7\x7c\xc0\x08\xdf\x7e\xac\x41\xd5\xce\xae\x06\xeb\x2c\xe9\x1c\x7e\xa9\x8d\x8c\x54\xdc\xa4\xdc\xad\x09\xfa\x8c\x41\xb7\x90\xf1\x37\xe3\x43\x08\xc8\x79\xbd\x12\x72\x66\x44\x20\x0f\x73\x44\x86\x00\xea\x11\x3a\x74\x18\x0c\x61\x03\x32\x5b\x91\xe5\xa7\x90\xfb\xc1\x18\x69\xb9\x5f\x34\x36\x08\x6e\x21\x9f\x2f\x29\x04\x1c\xc2\x9a\x7c\x78\xde\x43\x48\xb1\x3e\x7f\x37\x4d\xe8\x9a\x9b\xc1\xd6\x78\x6b\x86\x19\x73\x7d\xb6\x92\xca\xb9\x78\xb9\x0a\xcc\x57\xec\xf0\x09\x26\x43\x84\xc1\xc9\x90\x6b\x6a\x87\x76\x6d\x42\x44\x9d\xab\x97\x45\x01\xa1\xb6\x28\x80\x21\xc0\xe5\x15\xac\xea\x16\x9f\x56\x42\x3a\x4d\x97\xe4\x38\x20\xb0\x6b\xad\x36\xb6\x05\xa9\x7c\x75\x05\xce\x0e\x82\xb3\xe1\xad\x16\x1f\x27\xa6\x4d\xad\xf6\x91\x15\x68\xf8\x07\x3c\xd9\xeb\x87\xef\xa2\x22\x3f\xb8\x6c\xc3\x99\x0f\x4f\xac\xfe\x5b\x7e\xbc\xf0\x34\xaa\x2c\xa1\xf2\x21\xf8\x47\xd6\xb0\xe5\x7d\x43\x4f\x34\xc5\xcb\xb2\x3c\x30\xc3\x4f\x42\x9c\x1f\xd1\xad\x36\x68\x0c\x99\xb2\x1a\x7c\x55\x8e\x26\x32\xdf\xc3\xf0\xb1\x5e\x45\xe7\xa5\x85\x0e\x78\xf1\xdf\x36\xbd\x89\xbd\xad\x7d\x98\xca\x88\xa1\xfd\xab\x03\xa7\x47\xe3\x9a\x92\x6d\xe0\xa8\x14\x45\xef\xa2\xf4\xb8\x7b\x58\x9b\xe4\x89\xc9\x71\x77\x60\xf7\x0f\x38\x72\x4d\x4c\x76\x59\x17\x9b\x32\x8e\x71\x5b\x53\x23\x30\x2e\x98\x61\xf0\x8f\x11\xc6\x79\x20\xcb\x15\x82\x55\x73\x2c\xca\x26\xa5\x30\x8a\xf5\xd8\xd1\xd6\x54\x43\xf2\xa0\x49\x9d\xc0\xc0\x60\x23\x15\x8a\x9e\x27\x3c\xed\x7e\x64\x7b\x1d\xe1\xd4\x4f\xb0\x58\x95\xcd\xb0\xfc\x56\x76\x19\x90\x66\x76\xd1\xfa\xd7\x2c\x3e\x7b\x36\xcb\x79\xe4\x5d\x6e\x33\x71\xd0\x3f\xd1\x90\x74\xd2\x64\xad\xce\x65\xf1\x3e\x08\x2a\x5b\xe6\x3c\xc2\xd5\x1f\xc7\xc8\x8b\x9d\x78\x8f\x7a\x37\xe8\x16\xde\x6c\x61\xb1\x86\x5a\xd2\x0b\xcf\xd4\x3d\xc1\xe6\xfb\xe9\x18\x85\x67\xf9\x1d\x00\x00\xff\xff\xf1\xaa\x7d\x39\x6d\x04\x00\x00") 96 | 97 | func cmdGoBincodeMainGoBytes() ([]byte, error) { 98 | return bindataRead( 99 | _cmdGoBincodeMainGo, 100 | "cmd/go-bincode/main.go", 101 | ) 102 | } 103 | 104 | func cmdGoBincodeMainGo() (*asset, error) { 105 | bytes, err := cmdGoBincodeMainGoBytes() 106 | if err != nil { 107 | return nil, err 108 | } 109 | 110 | info := bindataFileInfo{name: "cmd/go-bincode/main.go", size: 1133, mode: os.FileMode(420), modTime: time.Unix(1440244452, 0)} 111 | a := &asset{bytes: bytes, info: info} 112 | return a, nil 113 | } 114 | 115 | var _genGo = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\x54\x91\x31\x6f\x83\x30\x10\x85\x67\xfc\x2b\xae\x4c\x20\x05\xd8\x91\x32\xb5\x6a\xa5\x4e\x95\x9a\xad\xea\xe0\xc2\x85\x58\x09\x3e\x74\x1c\x6d\xa5\x28\xff\xbd\x67\xe3\x24\x2a\x93\xf9\xde\xb3\xdf\xf3\xb9\x69\x06\x6a\x07\xf4\xc8\x56\x10\x06\x02\x5e\x3c\x74\x63\xaf\xb8\xfa\x72\xbe\xa3\x1e\x9b\xd1\x3a\x5f\xab\x54\x4d\xc7\x01\x12\x84\xca\x0d\x9e\x18\x41\x70\x96\x19\x2a\x5a\x64\x5a\xa4\xea\x1d\xaf\xc4\x4c\xb6\x3b\xda\x01\xaf\x7e\x63\xdc\x38\x11\x0b\xe4\x93\x95\x43\xb3\x77\x27\x0c\x8b\xdc\x98\xfd\xe2\x3b\x78\x49\x0d\x0a\x26\x92\x0d\x68\xd0\x06\xd6\x23\x9f\xf4\xc4\x59\xd8\x79\x25\x6b\xe4\x0c\x1f\x9f\x2b\x29\x01\x99\x89\xe1\x6c\xb2\xa6\x81\xdb\x2d\x62\x3f\xcb\xdd\xc1\x7d\xa3\xc9\xd4\x02\xed\x36\xf4\xe8\xad\x58\xb5\x66\x21\xa3\x85\xf8\xe5\x75\xbe\x51\xa2\x79\x09\xc4\x68\x25\xb7\xf0\xf6\xde\x23\xf0\x54\x21\xb8\xd3\x52\xe9\xa5\xc6\x5f\xec\x8a\xd2\x64\x6e\x1f\x2a\xc1\xc3\x16\xbc\x3b\x41\x0c\x43\x59\xd8\x07\xaa\x3e\xf3\xbf\x68\x9a\x8d\x2a\xc9\xf5\xc3\x4e\x70\x47\xcf\x3a\x9d\x42\xf7\x5e\xa7\x54\xbf\x92\xf3\xc5\xbd\x07\xe4\xd7\x9d\xfa\x2c\x79\x19\x7a\x85\xbf\x1d\x8e\xd3\x49\xcf\x9d\x6b\xa1\xf7\x38\xa0\x22\x6a\x6a\x7e\x54\xf9\xfc\xb6\x3e\x49\x1b\xee\x78\x51\xa1\x34\x17\xf3\x17\x00\x00\xff\xff\x50\x64\xdf\x8e\x00\x02\x00\x00") 116 | 117 | func genGoBytes() ([]byte, error) { 118 | return bindataRead( 119 | _genGo, 120 | "gen.go", 121 | ) 122 | } 123 | 124 | func genGo() (*asset, error) { 125 | bytes, err := genGoBytes() 126 | if err != nil { 127 | return nil, err 128 | } 129 | 130 | info := bindataFileInfo{name: "gen.go", size: 512, mode: os.FileMode(420), modTime: time.Unix(1440244488, 0)} 131 | a := &asset{bytes: bytes, info: info} 132 | return a, nil 133 | } 134 | 135 | var _templateGo = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\xac\x55\xcd\x6e\xdc\x36\x10\x3e\x4b\x4f\x31\xd1\xc1\x10\xd3\x8d\xec\x14\x49\x0b\x6c\xe1\x83\x1d\xdb\x68\x0f\xb5\x0b\xd8\x68\x0f\x81\xd1\x68\x77\xa9\x5d\x22\x5a\x52\x20\xa9\x38\xc6\x62\xdf\xbd\x33\x43\xea\xc7\xb1\x36\xf5\x21\x17\x89\x9c\x9f\x6f\x66\xbe\x19\x92\x4d\xb9\xfc\x5c\xae\x25\x2c\x94\x5e\x9a\x95\x4c\x53\xff\xd8\xf0\xee\x03\xee\xc0\x79\xdb\x2e\x3d\xec\xd2\xe4\xaf\x68\x87\x12\xa5\xd7\xe9\x3e\x1a\x7a\xb9\x6d\xea\xd2\x4b\x07\x1f\xef\x5f\x77\x9b\x34\xad\x5a\xbd\x84\xdc\xbb\x41\x2f\xc0\x9b\x5b\xf6\xcd\x45\x04\x21\xd8\x2f\xa5\xed\x6d\x3a\xec\xa4\x32\x16\xfe\x9d\x81\x87\xf9\x29\xd8\x52\x63\x54\x44\x42\xe3\xa4\xb7\x3c\x1d\x9c\x7e\x02\x5f\x78\xf9\xd5\xa7\xc9\x3e\x4d\xac\xf4\xad\xd5\xbd\x92\xd2\xa4\x08\x54\xd9\x5d\x9f\xe9\xe0\xec\x10\x34\x12\x70\xd7\xd4\xb3\x34\x51\xdb\xc6\x58\x1f\xd7\x5a\xc5\x55\x64\xc3\xf2\xee\xdb\xca\x47\x1c\xe9\x72\x3b\x14\x41\x39\x8d\xd8\xa2\x34\x86\x50\x98\xc3\x51\x07\x10\x1d\xe7\x90\x45\x7d\x36\x0b\xde\x73\xf8\x74\x7c\x0c\xdc\x87\xb5\xd4\xd2\xa2\xed\x0a\x16\x8f\xb0\x36\x6f\x62\xb7\x8a\x14\x0d\x2e\x6e\xe0\xfa\xe6\x0e\x2e\x2f\xfe\xb8\x7b\x95\x76\xed\xdc\xed\xa0\xe8\x5a\xb6\xdf\xa7\x9f\x62\x06\x7d\x7d\xd3\x09\x04\xf5\x28\x7e\x1a\x24\x90\xa7\x49\xb6\x78\x44\xc2\x32\x5c\x54\x75\xb9\xe6\xff\xd6\xd3\x4f\x99\x63\x65\x5a\xaf\x6a\xda\x18\xb6\x68\x4a\xbf\x39\xae\x54\x2d\x69\x41\x82\xc0\x03\xea\xc4\x90\x4a\xa0\xf7\x40\x22\xa8\x1c\xa7\xc1\xf3\x44\x42\x1c\x9e\x38\x35\xcb\x38\x9f\x4c\x36\x09\x6a\xe5\x3c\x2c\x8c\xa9\xc3\xd6\x4a\xe7\x8d\x95\x41\x82\x33\x45\xc3\x44\x99\x17\xd7\xf2\xe1\x0a\xff\xb7\xd2\xe7\xc6\x15\x67\x76\xed\x3e\x9e\xdc\xcf\x82\xee\x83\xd1\x5e\xe9\x56\xde\xe8\x4b\x6b\x8d\x15\xe4\x58\x84\xb1\xfd\xbb\xb4\xf9\x11\x05\x9d\x41\xe6\x36\xe6\xe1\x0d\xad\x33\xdc\x64\x51\x00\xce\xb4\x76\x29\x39\xb1\x4c\x90\xe3\x39\x86\x66\x37\x4a\x0d\xad\xe8\xd7\xb9\x55\x65\xed\x64\x94\x7d\xc7\x33\x56\x81\x86\x71\xf5\xad\x7f\x57\xe6\x53\x08\x9c\xd9\x96\x2b\x3e\xe2\xae\x15\xe7\x6d\x55\x49\xbb\xdb\x73\x39\xd2\xdf\xb4\xbe\x69\x7d\x8e\x36\x64\x2a\xad\x65\x72\x70\x60\xac\x93\x3d\x29\x6f\xe7\xf7\x98\x8b\xaa\x80\xf4\xaf\x4e\x41\xab\x9a\x0f\x21\xcf\x64\xa0\x09\x50\x4b\xbc\x81\x36\x1e\x2a\xd3\xea\x15\xea\x51\x16\xdb\xcd\x74\x96\x4a\xbb\x1c\x21\x0a\x66\x34\x17\x98\x33\xbb\x34\xd6\x7c\x51\x2b\x9a\xe8\xd6\xb3\xff\x4a\x56\x4a\xcb\xd5\x3c\xe3\x16\x27\xf1\x2c\xe3\x6a\x7f\x20\xa8\x72\x90\x6d\x32\xc0\xcb\x22\xdb\xc8\xba\xc9\x42\x6c\xca\xf6\x34\xb6\x1a\x43\xfe\x8e\x9a\x80\x87\xe3\x5a\x5c\x35\x98\x98\xaf\x35\x15\x79\xeb\xf1\x48\xdb\x19\xc6\xef\x5a\x9c\x0b\x31\x15\xf8\xf2\xab\xf2\x7d\xd0\x4d\xe9\x28\x84\xb1\xe9\xcb\x11\x51\x45\x18\xf9\xcf\x82\x2e\x29\xe6\x94\xdb\x4e\x69\x69\xf9\x70\x1e\xaf\x97\x5c\x14\x24\xa6\x75\x3e\x76\x3b\x19\xdc\x78\xe8\xb1\x17\x59\xc6\xce\xb1\x73\x4f\x31\x68\x16\x19\x83\x8c\xc5\x40\xca\xa8\x85\x07\x33\xc7\x0f\x53\xd0\x85\x7e\x2b\x22\x0d\x13\xb9\x74\x93\xf7\xbc\x8a\xa8\xe9\x0b\xf9\xf1\x09\x0c\x37\xda\xe8\x6e\x9e\xbe\x4a\x3a\x83\xf1\x75\x32\x7e\xe3\xec\xe8\x02\x7f\xb0\xca\xa3\x40\x99\xe2\x1f\x5e\xd1\xc5\xcd\x57\xcf\x93\xfa\xe0\x75\xef\xba\xeb\x9f\x9c\xa3\x4e\xb6\x0b\x20\x73\x08\x55\xe1\xcd\xb8\xef\x61\xf2\x45\x1f\x55\xc0\xd0\x6b\x82\x89\x6f\x5e\x39\xbc\x79\x67\xce\x49\x7f\x8d\x45\xb8\x60\x91\x2c\x0a\x04\xcb\xcb\x48\xc0\x04\x62\xdf\xf9\xd1\x43\x24\xc2\xb4\x12\x40\x49\x80\x4c\x31\x05\x61\x78\xb6\x9c\x3c\xe5\xb1\x2c\x94\xf2\xc3\x1a\x62\x07\xc8\x9c\x81\x68\xb2\xa3\x11\xfa\x4c\x27\xf4\x64\x10\x86\x44\x62\xad\x9c\xe5\xe1\x72\xf1\xe4\x6d\x3f\xaf\x94\x1d\x06\x08\x6d\x91\xd4\x3f\x49\x78\x56\xd7\x79\xf7\xc0\x14\x17\xca\x86\x42\x66\x70\xf2\xeb\xfb\xf7\xe2\xb7\x67\xe3\x36\xae\xa6\x3b\xd6\xdc\x27\x20\x10\xdc\x7f\x87\x9b\xa9\xf1\x7d\x86\xc7\xb7\x0e\x84\x77\x30\x0c\xcf\x15\x02\x33\x04\x36\x35\x80\x9f\xfc\xf2\xee\xdd\x0b\xf1\xf6\xff\xcf\x2d\xf7\xa3\x6f\x32\xb1\x3a\x3e\x52\x8b\x22\x8c\xe1\x0c\x9c\x08\xa7\xe5\xbf\x00\x00\x00\xff\xff\xcf\x51\xb7\x6c\xe9\x09\x00\x00") 136 | 137 | func templateGoBytes() ([]byte, error) { 138 | return bindataRead( 139 | _templateGo, 140 | "template.go", 141 | ) 142 | } 143 | 144 | func templateGo() (*asset, error) { 145 | bytes, err := templateGoBytes() 146 | if err != nil { 147 | return nil, err 148 | } 149 | 150 | info := bindataFileInfo{name: "template.go", size: 2537, mode: os.FileMode(420), modTime: time.Unix(1440245822, 0)} 151 | a := &asset{bytes: bytes, info: info} 152 | return a, nil 153 | } 154 | 155 | var _writerGo = []byte("\x1f\x8b\x08\x00\x00\x09\x6e\x88\x00\xff\x8c\x92\xbf\x8e\xdb\x30\x0c\xc6\x67\xeb\x29\x54\x0f\x85\x0c\x18\xca\xde\xe2\x96\x0b\x9a\xad\xc5\x0d\x07\xdc\x50\x74\xb0\x1d\xca\x27\x54\xb1\x02\x8a\xae\x53\x14\xf7\xee\x25\x65\xc7\x4d\xff\xa4\x97\x25\xa1\x25\x8a\xfc\x7d\x1f\x79\x6c\xba\xaf\x4d\x0f\xba\xf5\x43\x17\xf7\xa0\x94\x3f\x1c\x23\x92\x36\xaa\x28\xdb\xd1\xf9\x58\x4a\xf0\x9d\x20\x49\x30\x7f\x46\x89\xe9\x70\x0c\xba\x24\x38\xd1\x86\x80\xe3\x86\xa0\x54\x7c\xd9\xc7\xd0\x0c\xbd\x8d\xd8\x6f\x4e\x1b\x8a\x31\xa4\xcd\x5c\x92\x1f\x55\x4a\xb9\x71\xe8\xf4\x84\x9e\xe0\x31\xee\x7c\x00\xe3\xf8\xa7\xd6\xe7\x12\x3a\x11\xfa\xa1\xaf\x85\x67\xcb\x3c\xe7\xff\x4a\x03\x62\x44\xfd\x43\x15\xae\x96\x58\xbf\xbb\xd3\x31\xd9\x2d\x02\xbf\xca\x45\x2a\x55\x78\x97\xaf\xde\xdc\xe9\xc1\x07\xc9\x2d\x10\x68\xc4\x41\x4e\x55\xf1\xa2\x8a\x3d\x38\x40\xed\xec\x36\xc4\x04\x86\x71\x8a\x49\x0a\x65\xa1\xf6\x13\x4c\x4f\x02\x86\xc6\x55\xe7\xd4\xc9\xee\xc2\x98\x9e\x73\x6a\xbb\x36\xce\xfc\x4f\x9e\x9e\x77\x11\x0f\x0d\xfd\xa1\x61\x85\xbf\x81\x88\x01\x6c\x6e\x6a\x5a\xce\x5e\xee\x38\x55\xbd\x5c\x5a\x75\xb5\xd5\x75\xbb\xcc\xe7\x2f\x32\xb5\x7a\xf6\xad\x92\xd6\xdf\x1a\xd4\xad\xce\xb3\xb4\xf7\xa3\x63\x79\x57\xe4\xbf\x6d\xb3\x33\x19\x6b\xfa\xb7\xae\x4b\x5f\x5c\x26\x23\xd8\xaf\xfe\x2c\x03\xb7\x0f\x18\x3b\x48\x69\x81\x6e\xed\xbd\xf4\x36\x55\x2d\x0a\xff\x67\x0e\x7f\xd6\xeb\xcc\x96\xb3\x8b\x2e\x7f\xf9\x63\x26\xcd\x02\x66\x7a\xe6\x3d\x86\x47\x5e\xcb\x1b\x56\x89\x33\x05\x57\x56\xd9\x7e\x1c\x13\x99\x1c\xb1\x11\xa6\xa4\xb2\xb2\x0f\x0d\xf2\x96\x2c\xe5\xaa\x5f\xc0\xf2\x84\xf3\x3e\x9c\xa0\x1b\x67\x8b\xce\xa5\xdf\xbf\x36\xed\xdf\x26\xfc\x33\x00\x00\xff\xff\xe5\xa0\xd4\x32\x7c\x03\x00\x00") 156 | 157 | func writerGoBytes() ([]byte, error) { 158 | return bindataRead( 159 | _writerGo, 160 | "writer.go", 161 | ) 162 | } 163 | 164 | func writerGo() (*asset, error) { 165 | bytes, err := writerGoBytes() 166 | if err != nil { 167 | return nil, err 168 | } 169 | 170 | info := bindataFileInfo{name: "writer.go", size: 892, mode: os.FileMode(420), modTime: time.Unix(1440236164, 0)} 171 | a := &asset{bytes: bytes, info: info} 172 | return a, nil 173 | } 174 | 175 | // Asset loads and returns the asset for the given name. 176 | // It returns an error if the asset could not be found or 177 | // could not be loaded. 178 | func Asset(name string) ([]byte, error) { 179 | cannonicalName := strings.Replace(name, "\\", "/", -1) 180 | if f, ok := _bindata[cannonicalName]; ok { 181 | a, err := f() 182 | if err != nil { 183 | return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err) 184 | } 185 | return a.bytes, nil 186 | } 187 | return nil, fmt.Errorf("Asset %s not found", name) 188 | } 189 | 190 | // MustAsset is like Asset but panics when Asset would return an error. 191 | // It simplifies safe initialization of global variables. 192 | func MustAsset(name string) []byte { 193 | a, err := Asset(name) 194 | if (err != nil) { 195 | panic("asset: Asset(" + name + "): " + err.Error()) 196 | } 197 | 198 | return a 199 | } 200 | 201 | // AssetInfo loads and returns the asset info for the given name. 202 | // It returns an error if the asset could not be found or 203 | // could not be loaded. 204 | func AssetInfo(name string) (os.FileInfo, error) { 205 | cannonicalName := strings.Replace(name, "\\", "/", -1) 206 | if f, ok := _bindata[cannonicalName]; ok { 207 | a, err := f() 208 | if err != nil { 209 | return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err) 210 | } 211 | return a.info, nil 212 | } 213 | return nil, fmt.Errorf("AssetInfo %s not found", name) 214 | } 215 | 216 | // AssetNames returns the names of the assets. 217 | func AssetNames() []string { 218 | names := make([]string, 0, len(_bindata)) 219 | for name := range _bindata { 220 | names = append(names, name) 221 | } 222 | return names 223 | } 224 | 225 | // _bindata is a table, holding each asset generator, mapped to its name. 226 | var _bindata = map[string]func() (*asset, error){ 227 | "bindata.go": bindataGo, 228 | "cmd/go-bincode/main.go": cmdGoBincodeMainGo, 229 | "gen.go": genGo, 230 | "template.go": templateGo, 231 | "writer.go": writerGo, 232 | } 233 | 234 | // AssetDir returns the file names below a certain 235 | // directory embedded in the file by go-bindata. 236 | // For example if you run go-bindata on data/... and data contains the 237 | // following hierarchy: 238 | // data/ 239 | // foo.txt 240 | // img/ 241 | // a.png 242 | // b.png 243 | // then AssetDir("data") would return []string{"foo.txt", "img"} 244 | // AssetDir("data/img") would return []string{"a.png", "b.png"} 245 | // AssetDir("foo.txt") and AssetDir("notexist") would return an error 246 | // AssetDir("") will return []string{"data"}. 247 | func AssetDir(name string) ([]string, error) { 248 | node := _bintree 249 | if len(name) != 0 { 250 | cannonicalName := strings.Replace(name, "\\", "/", -1) 251 | pathList := strings.Split(cannonicalName, "/") 252 | for _, p := range pathList { 253 | node = node.Children[p] 254 | if node == nil { 255 | return nil, fmt.Errorf("Asset %s not found", name) 256 | } 257 | } 258 | } 259 | if node.Func != nil { 260 | return nil, fmt.Errorf("Asset %s not found", name) 261 | } 262 | rv := make([]string, 0, len(node.Children)) 263 | for childName := range node.Children { 264 | rv = append(rv, childName) 265 | } 266 | return rv, nil 267 | } 268 | 269 | type bintree struct { 270 | Func func() (*asset, error) 271 | Children map[string]*bintree 272 | } 273 | var _bintree = &bintree{nil, map[string]*bintree{ 274 | "bindata.go": &bintree{bindataGo, map[string]*bintree{ 275 | }}, 276 | "cmd": &bintree{nil, map[string]*bintree{ 277 | "go-bincode": &bintree{nil, map[string]*bintree{ 278 | "main.go": &bintree{cmdGoBincodeMainGo, map[string]*bintree{ 279 | }}, 280 | }}, 281 | }}, 282 | "gen.go": &bintree{genGo, map[string]*bintree{ 283 | }}, 284 | "template.go": &bintree{templateGo, map[string]*bintree{ 285 | }}, 286 | "writer.go": &bintree{writerGo, map[string]*bintree{ 287 | }}, 288 | }} 289 | 290 | // RestoreAsset restores an asset under the given directory 291 | func RestoreAsset(dir, name string) error { 292 | data, err := Asset(name) 293 | if err != nil { 294 | return err 295 | } 296 | info, err := AssetInfo(name) 297 | if err != nil { 298 | return err 299 | } 300 | err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755)) 301 | if err != nil { 302 | return err 303 | } 304 | err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode()) 305 | if err != nil { 306 | return err 307 | } 308 | err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime()) 309 | if err != nil { 310 | return err 311 | } 312 | return nil 313 | } 314 | 315 | // RestoreAssets restores an asset under the given directory recursively 316 | func RestoreAssets(dir, name string) error { 317 | children, err := AssetDir(name) 318 | // File 319 | if err != nil { 320 | return RestoreAsset(dir, name) 321 | } 322 | // Dir 323 | for _, child := range children { 324 | err = RestoreAssets(dir, filepath.Join(name, child)) 325 | if err != nil { 326 | return err 327 | } 328 | } 329 | return nil 330 | } 331 | 332 | func _filePath(dir, name string) string { 333 | cannonicalName := strings.Replace(name, "\\", "/", -1) 334 | return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...) 335 | } 336 | 337 | --------------------------------------------------------------------------------