{"id":41077447,"url":"https://github.com/nikasulo/embedfiles","last_synced_at":"2026-01-22T13:31:57.513Z","repository":{"id":57614687,"uuid":"380722935","full_name":"nikasulo/embedfiles","owner":"nikasulo","description":"A simple go package to help with embedding static files like `.html` files in go binaries","archived":false,"fork":false,"pushed_at":"2021-07-10T13:10:44.000Z","size":34,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-06-21T09:59:21.872Z","etag":null,"topics":["embedfiles","go","golang"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nikasulo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-06-27T11:30:49.000Z","updated_at":"2021-07-10T12:48:55.000Z","dependencies_parsed_at":"2022-08-27T03:24:37.768Z","dependency_job_id":null,"html_url":"https://github.com/nikasulo/embedfiles","commit_stats":null,"previous_names":["oluwadamilareolusakin/embedfiles"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/nikasulo/embedfiles","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikasulo%2Fembedfiles","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikasulo%2Fembedfiles/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikasulo%2Fembedfiles/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikasulo%2Fembedfiles/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nikasulo","download_url":"https://codeload.github.com/nikasulo/embedfiles/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nikasulo%2Fembedfiles/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28663785,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-22T01:17:37.254Z","status":"online","status_checked_at":"2026-01-22T02:00:07.137Z","response_time":144,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["embedfiles","go","golang"],"created_at":"2026-01-22T13:31:56.835Z","updated_at":"2026-01-22T13:31:57.466Z","avatar_url":"https://github.com/nikasulo.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Embedfiles\n\nA simple go package that embeds static files in Go Binaries for packaging and easy release of software\n\n## Use\n#### Install the package\nThere are two ways you can go about this:\n1. You can install from the command line by running `$ go get github.com/oluwadamilareolusakin/embedfiles`\n2. You can add a go generate directive to your go binary after your last import statement `//go:generate go get github.com/oluwadamilareolusakin/embedfiles`. We will talk about how to run this in a second.\n\n#### Point it at your static files\nAdd a `go generate` directive to your go binary `//go:generate embedfiles \"see_first_arg_description_below\" \"path_to_static_files\" \"see_third_arg_description_below\"\n\n##### First arg description\nThe first argument to your command is the path where you want your newly generated package to live and be accessed from. Say I had a module called blog, which I want to embed files for. My folder structure may look something like:\n```\nblog                          # Top-level module name\n├── ...\n├── templates                 \n│   ├── index.html            # shows all blog posts\n│   ├── new.html              # Renders form to create new blog post\n│   └── ...\n├── server                    # Handles browser requests\n│   ├── server.go        \n│   ├── server_test.go \n├── pageio                    # Handles storing and retrieving blog pages\n│   ├── pageio.go\n├── ...\n```\n\nIn this case, I may decide to add a subdirectory to `/blog/` named `statictemplates` as my new package name. Then my first argument may look like `../statictemplates/template.go`. My file structure then becomes:\n\n```\nblog                          # Top-level module name\n├── ...\n├── templates                 \n│   ├── index.html            # shows all blog posts\n│   ├── new.html              # Renders form to create new blog post\n│   └── ...\n├── server                    # Handles browser requests\n│   ├── server.go        \n│   ├── server_test.go \n├── pageio                    # Handles storing and retrieving blog pages\n│   ├── pageio.go\n├── statictemplates           # Directory and package file created after I run `go generate`\n│   ├── template.go\n├── ...\n\n##### Third arg description\nThe third argument is the name of the package we mentioned above, in our case \"statictemplates\". This will ensure that our `tempate.go` file looks something like:\n```\n\n```\npackage statictemplates\n\n....\n......\n```\nPutting it together, my go generate directives may look like in `server.go`: \n```\n//go:generate go get \"github.com/oluwadamilareolusakin/embedfiles\"\n//go:generate embedfiles \"../statictemplates/template.go\" \"../templates\" \"statictemplates\"\n```\n\n#### Running the generate command\nAfter you have completed all the steps above, you may run your generate command. In the root of your module, in our case `/blog/` you may run `$ go generate ./...`\nThis command will search for all `go generate` directives in the directory and run them. To confirm this worked, you can checkout `/blog/statictemplates/template.go` and you should see something like:\n\n```\npackage statictemplates\n\n// Code generated by go generate, DO NOT EDIT\n\nfunc init() {\n\tvault.Add(\"/404.html\", []byte{60, 104, 49, 62, 87, 104, 111, 111...})\n  \t...\n}\n\ntype Vault struct {\n\tstorageUnit map[string][]byte\n}\n\nfunc newVault() *Vault {\n\treturn \u0026Vault{storageUnit: make(map[string][]byte)}\n}\n\nfunc (vault *Vault) Add(filename string, content []byte) {\n\tvault.storageUnit[filename] = content\n}\n\nfunc (vault *Vault) GetFile(filename string) []byte {\n\treturn vault.storageUnit[filename]\n}\n\nvar vault = newVault()\n\nfunc Add(filename string, content []byte) {\n\tvault.Add(filename, content)\n}\n\nfunc Get(filename string) []byte {\n\treturn vault.GetFile(filename)\n}\n```\nYou can now use all the embedded files and the methods from the `statictemplates` package throughout your program. Et Voila! You have generated a go binary that has your static files embedded as bytes 🎉\n\nTo use these files in your program, follow these steps:\n\n## Add your new package to the imports of the files you wish to use your embedded files in\n\nFor example, if we want to use the files in `server.go` we may add the package import:\n```\npackage main\n\nimport (\n\t\"fmt\"\n\t\"html/template\"\n\t\"log\"\n\t\"net/http\"\n    \"regexp\"\n\t\"github.com/oluwadamilareolusakin/gowiki/pageio\"\n\t\"github.com/oluwadamilareolusakin/gowiki/statictemplates\" // import added\n)\n```\n## Fetch your embedded files for use\nAn example could be rendering a template for the `404.html` template we embedded:\n\n```\nfunc renderTemplate(w http.ResponseWriter, title string, page *pageio.Page) {\n\n  templateKey := \"/\" + title + \".html\" // something like \"/404.html\"\n  data := string(statictemplates.Get(templateKey)) // using the .Get method from statictemplates\n  templ := template.Must(template.New(\"\").Parse(data))\n  err := templ.Execute(w, page)\n\n  handleError(w, err)\n}\n```\n\nThere you have it, you can now ship your apps without worrying about copying over static files and publishing them! Happy Tinkering! 🚀 \n\nIf you have some feedback or suggestions, I'd love to hear them, you can shoot me a mail `projects@oluwadamilareolusakin.com` or find me on [Twitter](https://twitter.com/damiolusakin)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikasulo%2Fembedfiles","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnikasulo%2Fembedfiles","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnikasulo%2Fembedfiles/lists"}