{"id":15034959,"url":"https://github.com/shulhan/go-bindata","last_synced_at":"2025-08-03T01:04:11.904Z","repository":{"id":24953890,"uuid":"102852147","full_name":"shuLhan/go-bindata","owner":"shuLhan","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":"2022-07-16T16:00:46.000Z","size":1381,"stargazers_count":190,"open_issues_count":2,"forks_count":25,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-09T22:52:38.907Z","etag":null,"topics":["go","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"gnoso/go-bindata","license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shuLhan.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-08T10:58:58.000Z","updated_at":"2025-03-31T05:17:22.000Z","dependencies_parsed_at":"2022-08-07T11:01:29.568Z","dependency_job_id":null,"html_url":"https://github.com/shuLhan/go-bindata","commit_stats":null,"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shuLhan%2Fgo-bindata","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shuLhan%2Fgo-bindata/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shuLhan%2Fgo-bindata/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shuLhan%2Fgo-bindata/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shuLhan","download_url":"https://codeload.github.com/shuLhan/go-bindata/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248125640,"owners_count":21051766,"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":["go","golang"],"created_at":"2024-09-24T20:27:01.155Z","updated_at":"2025-04-09T22:52:43.449Z","avatar_url":"https://github.com/shuLhan.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Documentation](https://godoc.org/github.com/shuLhan/go-bindata?status.svg)](http://godoc.org/github.com/shuLhan/go-bindata)\n[![Go Report Card](https://goreportcard.com/badge/github.com/shuLhan/go-bindata)](https://goreportcard.com/report/github.com/shuLhan/go-bindata)\n\n## bindata\n\nThis package converts any file into managable 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` sub directory.\nThis tool offers a set of command line options, used to customize the\noutput being generated.\n\n\n### Installation\n\nTo install the library and command line program, use the following:\n\n\tgo get -u github.com/shuLhan/go-bindata/...\n\nFor Go 1.13 and beyond that use Go module,\n\n\tgo install github.com/shuLhan/go-bindata/v4/cmd/go-bindata\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 elipsis 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, we use the following:\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 behaviour is to use the old code generation method. This\nprevents the two previously mentioned issues, but will employ at least one\nextra memcopy and thus 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 behaviour 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 passed\nto `go-bindata`. This includes the path. In most cases, this is not desireable,\nas it puts potentially sensitive information in your code base.  For this\npurpose, the tool supplies another command line flag `-prefix`.  This accepts a\n[regular expression](https://github.com/google/re2/wiki/Syntax) string, which\nwill be used to match a portion of the map keys and function names that should\nbe stripped out.\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 \"/.*/some/\" /a/path/to/some/templates/\n\n\t_bindata[\"templates/foo.html\"] = templates_foo_html\n\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\n`net/http`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshulhan%2Fgo-bindata","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshulhan%2Fgo-bindata","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshulhan%2Fgo-bindata/lists"}