a simple url shortener in Go (check it out at qurl.org)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
2.9 KiB

  1. # bindata
  2. [![GoDoc](https://godoc.org/github.com/simleb/bindata?status.svg)](http://godoc.org/github.com/simleb/bindata)
  3. [![Coverage Status](https://coveralls.io/repos/github/simleb/bindata/badge.svg?branch=master)](https://coveralls.io/github/simleb/bindata?branch=master)
  4. [![Build Status](https://drone.io/github.com/simleb/bindata/status.png)](https://drone.io/github.com/simleb/bindata/latest)
  5. [![Go Report Card](https://goreportcard.com/badge/github.com/simleb/bindata)](https://goreportcard.com/report/github.com/simleb/bindata)
  6. The `bindata` command embeds binary files as byte arrays into a Go source file.
  7. It is designed with go generate in mind, but can be used on its own as well.
  8. The data is stored as a map of byte slices or strings indexed by the file paths as specified on the command line. The default name of the map is `bindata` but a custom name can be specified on the command line (`-m`).
  9. Multiple files and directories can be provided on the command line. Directories are treated recursively. The keys of the map are the paths of the files relative to the current directory. A different root for the paths can be specified on the command line (`-r`).
  10. By default, the data are saved as byte slices. It is also possible to save them a strings (`-s`).
  11. By default, the package name of the file containing the generate directive is used as the package name of the generated file, or `main` otherwise. A custom package name can also be specified on the command line (`-p`).
  12. The output file can be specified on the command line (`-o`). If a file already exists at this location, it will be overwritten. The file produced is properly formatted and commented. If no output file is specified, the contents are printed on the standard output.
  13. To see the full list of flags, run:
  14. bindata -h
  15. ## Example
  16. Given a file `hello.go` containing:
  17. package main
  18. import "fmt"
  19. func main() {
  20. fmt.Println("Hello, 世界")
  21. }
  22. Running `bindata hello.go` will produce:
  23. package main
  24. // This file is generated. Do not edit directly.
  25. // bindata stores binary files as byte slices indexed by filepaths.
  26. var bindata = map[string][]byte{
  27. "hello.go": []byte{
  28. 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x20, 0x6d, 0x61, 0x69, 0x6e,
  29. 0x0a, 0x0a, 0x69, 0x6d, 0x70, 0x6f, 0x72, 0x74, 0x20, 0x22, 0x66, 0x6d,
  30. 0x74, 0x22, 0x0a, 0x0a, 0x66, 0x75, 0x6e, 0x63, 0x20, 0x6d, 0x61, 0x69,
  31. 0x6e, 0x28, 0x29, 0x20, 0x7b, 0x0a, 0x09, 0x66, 0x6d, 0x74, 0x2e, 0x50,
  32. 0x72, 0x69, 0x6e, 0x74, 0x6c, 0x6e, 0x28, 0x22, 0x48, 0x65, 0x6c, 0x6c,
  33. 0x6f, 0x2c, 0x20, 0xe4, 0xb8, 0x96, 0xe7, 0x95, 0x8c, 0x22, 0x29, 0x0a,
  34. 0x7d, 0x0a,
  35. },
  36. }
  37. ## Example using Go generate
  38. Add a command like this one anywhere in a source file:
  39. //go:generate bindata -o jpegs.go pic1.jpg pic2.jpg pic3.jpg
  40. Then simply run `go generate` and the file `jpegs.go` will be created.
  41. ## Todo (maybe)
  42. - [ ] add option to compress data (but then need accessor)
  43. ## License
  44. The MIT License (MIT). See [LICENSE.txt](LICENSE.txt).