{"id":17138460,"url":"https://github.com/kevinburke/go-bindata","last_synced_at":"2025-05-07T10:42:15.791Z","repository":{"id":27035518,"uuid":"74229876","full_name":"kevinburke/go-bindata","owner":"kevinburke","description":"A small utility which generates Go code from any file. Useful for embedding binary data in a Go program.","archived":false,"fork":false,"pushed_at":"2023-03-24T18:25:37.000Z","size":26060,"stargazers_count":346,"open_issues_count":20,"forks_count":30,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-31T09:11:12.600Z","etag":null,"topics":["golang","static-files"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kevinburke.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.txt","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-11-19T19:20:03.000Z","updated_at":"2025-02-28T22:41:29.000Z","dependencies_parsed_at":"2024-06-18T12:48:25.709Z","dependency_job_id":null,"html_url":"https://github.com/kevinburke/go-bindata","commit_stats":{"total_commits":246,"total_committers":46,"mean_commits":"5.3478260869565215","dds":0.6178861788617886,"last_synced_commit":"2394b8291982849e5d021d3e2cee870ce63fe8a2"},"previous_names":[],"tags_count":47,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinburke%2Fgo-bindata","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinburke%2Fgo-bindata/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinburke%2Fgo-bindata/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kevinburke%2Fgo-bindata/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kevinburke","download_url":"https://codeload.github.com/kevinburke/go-bindata/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252862037,"owners_count":21815783,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","static-files"],"created_at":"2024-10-14T20:09:42.384Z","updated_at":"2025-05-07T10:42:15.741Z","avatar_url":"https://github.com/kevinburke.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## bindata\n\n*This fork is maintained by Kevin Burke, and is the version trusted by Homebrew.\nChanges made include:*\n\n- Atomic writes; generated file cannot be read while partially complete.\n\n- Better encoding of files that contain characters in the Unicode format range.\n\n- Generated file reports file sizes.\n\n- Generated code is run through go fmt.\n\n- SHA256 hashes are computed for all files and stored in the binary. You can\nuse this to detect in-memory corruption and to provide easy cache-busting\nmechanisms.\n\n- Added AssetString and MustAssetString functions.\n\n- ByName is not public.\n\n- Some errors in file writes were unchecked, but are now checked.\n\n- File modes are stored in octal (0644) instead of nonsensical decimal (420)\n\nThis package converts any file into manageable Go source code. Useful for\nembedding binary data into a go program. The file data is optionally gzip\ncompressed before being converted to a raw byte slice.\n\nIt comes with a command line tool in the `go-bindata` subdirectory. This tool\noffers a set of command line options, used to customize the output being\ngenerated.\n\n\n### Installation\n\nOn Macs, you can install the binary using [Homebrew](https://brew.sh):\n\n```\nbrew install go-bindata\n```\n\nYou can also download a binary from the [releases page][releases]. Switch in\nyour GOOS for the word \"linux\" below, and the latest version for the version\nlisted below:\n\n```\ncurl --silent --location --output /usr/local/bin/go-bindata https://github.com/kevinburke/go-bindata/releases/download/v4.0.0/go-bindata-linux-amd64\nchmod 755 /usr/local/bin/go-bindata\n```\n\nAlternatively, if you have a working Go installation, you can build the source and install the executable into `$GOPATH/bin` or `$GOBIN`:\n\n```shell\ngo install github.com/kevinburke/go-bindata/v4/...@latest\n# for versions of Go \u003c 1.11, or without module support, use:\ngo install github.com/kevinburke/go-bindata/...\n```\n\n[releases]: https://github.com/kevinburke/go-bindata/releases\n\n### Usage\n\nConversion is done on one or more sets of files. They are all embedded in a new\nGo source file, along with a table of contents and an `Asset` function,\nwhich allows quick access to the asset, based on its name.\n\nThe simplest invocation generates a `bindata.go` file in the current\nworking directory. It includes all assets from the `data` directory.\n\n\t$ go-bindata data/\n\nTo include all input sub-directories recursively, use the ellipsis postfix\nas defined for Go import paths. Otherwise it will only consider assets in the\ninput directory itself.\n\n\t$ go-bindata data/...\n\nTo specify the name of the output file being generated, use the `-o` option:\n\n\t$ go-bindata -o myfile.go data/\n\nMultiple input directories can be specified if necessary.\n\n\t$ go-bindata dir1/... /path/to/dir2/... dir3\n\n\nThe following paragraphs detail some of the command line options which can be\nsupplied to `go-bindata`. Refer to the `testdata/out` directory for various\noutput examples from the assets in `testdata/in`. Each example uses different\ncommand line options.\n\nTo ignore files, pass in regexes using -ignore, for example:\n\n    $ go-bindata -ignore=\\\\.gitignore data/...\n\n### Accessing an asset\n\nTo access asset data, we use the `Asset(string) ([]byte, error)` function which\nis included in the generated output.\n\n\tdata, err := Asset(\"pub/style/foo.css\")\n\tif err != nil {\n\t\t// Asset was not found.\n\t}\n\n\t// use asset data\n\n\n### Debug vs Release builds\n\nWhen invoking the program with the `-debug` flag, the generated code does\nnot actually include the asset data. Instead, it generates function stubs\nwhich load the data from the original file on disk. The asset API remains\nidentical between debug and release builds, so your code will not have to\nchange.\n\nThis is useful during development when you expect the assets to change often.\nThe host application using these assets uses the same API in both cases and\nwill not have to care where the actual data comes from.\n\nAn example is a Go webserver with some embedded, static web content like\nHTML, JS and CSS files. While developing it, you do not want to rebuild the\nwhole server and restart it every time you make a change to a bit of\njavascript. You just want to build and launch the server once. Then just press\nrefresh in the browser to see those changes. Embedding the assets with the\n`debug` flag allows you to do just that. When you are finished developing and\nready for deployment, just re-invoke `go-bindata` without the `-debug` flag.\nIt will now embed the latest version of the assets.\n\n\n### Lower memory footprint\n\nUsing the `-nomemcopy` flag, will alter the way the output file is generated.\nIt will employ a hack that allows us to read the file data directly from\nthe compiled program's `.rodata` section. This ensures that when we\ncall our generated function, we omit unnecessary memcopies.\n\nThe downside of this, is that it requires dependencies on the `reflect` and\n`unsafe` packages. These may be restricted on platforms like AppEngine and\nthus prevent you from using this mode.\n\nAnother disadvantage is that the byte slice we create, is strictly read-only.\nFor most use-cases this is not a problem, but if you ever try to alter the\nreturned byte slice, a runtime panic is thrown. Use this mode only on target\nplatforms where memory constraints are an issue.\n\nThe default behavior is to use the old code generation method. This prevents the\ntwo previously mentioned issues, but will employ at least one extra memcopy and\nthus increase memory requirements.\n\nFor instance, consider the following two examples:\n\nThis would be the default mode, using an extra memcopy but gives a safe\nimplementation without dependencies on `reflect` and `unsafe`:\n\n```go\nfunc myfile() []byte {\n    return []byte{0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a}\n}\n```\n\nHere is the same functionality, but uses the `.rodata` hack.\nThe byte slice returned from this example can not be written to without\ngenerating a runtime error.\n\n```go\nvar _myfile = \"\\x89\\x50\\x4e\\x47\\x0d\\x0a\\x1a\"\n\nfunc myfile() []byte {\n    var empty [0]byte\n    sx := (*reflect.StringHeader)(unsafe.Pointer(\u0026_myfile))\n    b := empty[:]\n    bx := (*reflect.SliceHeader)(unsafe.Pointer(\u0026b))\n    bx.Data = sx.Data\n    bx.Len = len(_myfile)\n    bx.Cap = bx.Len\n    return b\n}\n```\n\n\n### Optional compression\n\nWhen the `-nocompress` flag is given, the supplied resource is *not* GZIP\ncompressed before being turned into Go code. The data should still be accessed\nthrough a function call, so nothing changes in the usage of the generated file.\n\nThis feature is useful if you do not care for compression, or the supplied\nresource is already compressed. Doing it again would not add any value and may\neven increase the size of the data.\n\nThe default behavior of the program is to use compression.\n\n\n### Path prefix stripping\n\nThe keys used in the `_bindata` map, are the same as the input file name\npassed to `go-bindata`. This includes the path. In most cases, this is not\ndesireable, as it puts potentially sensitive information in your code base.\nFor this purpose, the tool supplies another command line flag `-prefix`.\nThis accepts a portion of a path name, which should be stripped off from\nthe map keys and function names.\n\nFor example, running without the `-prefix` flag, we get:\n\n\t$ go-bindata /path/to/templates/\n\n\t_bindata[\"/path/to/templates/foo.html\"] = path_to_templates_foo_html\n\nRunning with the `-prefix` flag, we get:\n\n\t$ go-bindata -prefix \"/path/to/\" /path/to/templates/\n\n\t_bindata[\"templates/foo.html\"] = templates_foo_html\n\n### Build tags\n\nWith the optional `-tags` flag, you can specify any go build tags that\nmust be fulfilled for the output file to be included in a build. This\nis useful when including binary data in multiple formats, where the desired\nformat is specified at build time with the appropriate tags.\n\nThe tags are appended to a `// +build` line in the beginning of the output file\nand must follow the build tags syntax specified by the go tool.\n\n### Related projects\n\n[go-bindata-assetfs](https://github.com/elazarl/go-bindata-assetfs#readme) -\nimplements `http.FileSystem` interface. Allows you to serve assets with `net/http`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinburke%2Fgo-bindata","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkevinburke%2Fgo-bindata","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkevinburke%2Fgo-bindata/lists"}