-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add `-split` option to avoid generating big file * Modifications following first code review
- Loading branch information
1 parent
e134b7c
commit 94068b1
Showing
8 changed files
with
318 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
package bindata | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
// translateToDir generates splited file | ||
func translateToDir(c *Config, toc []Asset, wd string) error { | ||
if err := generateCommonFile(c, toc); err != nil { | ||
return err | ||
} | ||
|
||
for i := range toc { | ||
if err := generateOneAsset(c, &toc[i], wd); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func generateCommonFile(c *Config, toc []Asset) error { | ||
// Create output file. | ||
fd, err := os.Create(filepath.Join(c.Output, "bindata.go")) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
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, "// -- Common file --\n"); err != nil { | ||
return err | ||
} | ||
|
||
if _, err = fmt.Fprint(bfd, "// DO NOT EDIT!\n\n"); err != nil { | ||
return err | ||
} | ||
|
||
// Write build tags, if applicable. | ||
if len(c.Tags) > 0 { | ||
if _, err = fmt.Fprintf(bfd, "// +build %s\n\n", c.Tags); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
// Write package declaration. | ||
_, err = fmt.Fprintf(bfd, "package %s\n\n", c.Package) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Write assets. | ||
if c.Debug || c.Dev { | ||
err = writeDebugHeader(bfd) | ||
} else { | ||
err = writeReleaseHeader(bfd, c) | ||
} | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
// Write table of contents | ||
if err := writeTOC(bfd, toc); err != nil { | ||
return err | ||
} | ||
// Write hierarchical tree of assets | ||
if err := writeTOCTree(bfd, toc); err != nil { | ||
return err | ||
} | ||
|
||
// Write restore procedure | ||
return writeRestore(bfd) | ||
|
||
} | ||
|
||
func generateOneAsset(c *Config, a *Asset, wd string) error { | ||
// Create output file. | ||
fd, err := os.Create(filepath.Join(c.Output, a.Func + ".go")) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
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, "// source: "); err != nil { | ||
return err | ||
} | ||
|
||
relative, _ := filepath.Rel(wd, a.Path) | ||
if _, err = fmt.Fprintln(bfd, 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. | ||
if len(c.Tags) > 0 { | ||
if _, err = fmt.Fprintf(bfd, "// +build %s\n\n", c.Tags); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
// Write package declaration. | ||
_, err = fmt.Fprintf(bfd, "package %s\n\n", c.Package) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Write assets. | ||
if c.Debug || c.Dev { | ||
err = writeOneFileDebug(bfd, c, a) | ||
} else { | ||
err = writeOneFileRelease(bfd, c, a) | ||
} | ||
|
||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package bindata | ||
|
||
import ( | ||
"os" | ||
"bufio" | ||
"fmt" | ||
"path/filepath" | ||
) | ||
|
||
// translateToFile generates one single file | ||
func translateToFile(c *Config, toc []Asset, wd string) error { | ||
// Create output file. | ||
fd, err := os.Create(c.Output) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
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 | ||
} | ||
|
||
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. | ||
if len(c.Tags) > 0 { | ||
if _, err = fmt.Fprintf(bfd, "// +build %s\n\n", c.Tags); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
// Write package declaration. | ||
_, err = fmt.Fprintf(bfd, "package %s\n\n", c.Package) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Write assets. | ||
if c.Debug || c.Dev { | ||
err = writeDebug(bfd, c, toc) | ||
} else { | ||
err = writeRelease(bfd, c, toc) | ||
} | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
||
// Write table of contents | ||
if err := writeTOC(bfd, toc); err != nil { | ||
return err | ||
} | ||
// Write hierarchical tree of assets | ||
if err := writeTOCTree(bfd, toc); err != nil { | ||
return err | ||
} | ||
|
||
// Write restore procedure | ||
return writeRestore(bfd) | ||
} |
Oops, something went wrong.