toc.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // This work is subject to the CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
  2. // license. Its contents can be found at:
  3. // http://creativecommons.org/publicdomain/zero/1.0/
  4. package bindata
  5. import (
  6. "fmt"
  7. "io"
  8. "io/ioutil"
  9. "path/filepath"
  10. "strings"
  11. )
  12. // createTOC writes a table of contents file to the given location.
  13. func CreateTOC(dir, pkgname string) error {
  14. file := filepath.Join(dir, "bindata-toc.go")
  15. code := fmt.Sprintf(`package %s
  16. // Global Table of Contents map. Generated by go-bindata.
  17. // After startup of the program, all generated data files will
  18. // put themselves in this map. The key is the full filename, as
  19. // supplied to go-bindata.
  20. var go_bindata = make(map[string]func() []byte)`, pkgname)
  21. return ioutil.WriteFile(file, []byte(code), 0600)
  22. }
  23. // WriteTOCInit writes the TOC init function for a given data file
  24. // replacing the prefix in the filename by "", funcname being the translated function name
  25. func WriteTOCInit(output io.Writer, filename, prefix, funcname string) {
  26. filename = strings.Replace(filename, prefix, "", 1)
  27. fmt.Fprintf(output, `
  28. func init() {
  29. go_bindata[%q] = %s
  30. }
  31. `, filename, funcname)
  32. }