{"id":13756236,"url":"https://github.com/bouk/staticfiles","last_synced_at":"2025-05-10T03:31:12.845Z","repository":{"id":57482078,"uuid":"65221780","full_name":"bouk/staticfiles","owner":"bouk","description":"staticfiles compiles a directory of files into an embeddable .go file","archived":true,"fork":false,"pushed_at":"2021-01-06T10:42:49.000Z","size":137,"stargazers_count":507,"open_issues_count":1,"forks_count":17,"subscribers_count":11,"default_branch":"master","last_synced_at":"2024-08-03T11:01:49.209Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bouk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-08-08T16:46:11.000Z","updated_at":"2024-05-27T16:18:03.000Z","dependencies_parsed_at":"2022-09-02T04:20:16.183Z","dependency_job_id":null,"html_url":"https://github.com/bouk/staticfiles","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bouk%2Fstaticfiles","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bouk%2Fstaticfiles/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bouk%2Fstaticfiles/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bouk%2Fstaticfiles/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bouk","download_url":"https://codeload.github.com/bouk/staticfiles/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224911420,"owners_count":17390840,"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":[],"created_at":"2024-08-03T11:00:39.699Z","updated_at":"2024-11-16T11:31:21.710Z","avatar_url":"https://github.com/bouk.png","language":"Go","funding_links":[],"categories":["Go"],"sub_categories":[],"readme":"# DEPRECATED\n\nGo 1.16 has file embedding built-in, you should use that!\n\n# staticfiles\n\nStaticfiles allows you to embed a directory of files into your Go binary. It is optimized for performance and file size, and automatically compresses everything before embedding it. Here are some of its features:\n\n* Compresses files, to make sure the resulting binary isn't bloated. It only compresses files that are actually smaller when `gzip`ped.\n* Serves files `gzip`ped (while still allowing clients that don't support it to be served).\n* Ignores hidden files (anything that starts with `.`).\n* Fast. The command-line tool reads and compresses files in parallel, and the resulting Go file serves files very quickly, avoiding unnecessary allocations.\n* No built-in development mode, but makes it very easy to implement one (see [local development mode](#local-development-mode)).\n\nIt has some clever tricks, like only compressing a file if it actually makes the binary smaller (PNG files won't be compressed, as they already are and compressing them again will make them bigger).\n\nI recommend creating a separate package inside your project to serve as the container for the embedded files.\n\n## Example\n\nFor an example of how to use the resulting package, check out `example/example.go`. You can also see the API it generates at [godoc.org](https://godoc.org/bou.ke/staticfiles/files).\n\n## Installation\n\nInstall with\n\n```\ngo get bou.ke/staticfiles\n```\n\n## Usage\n\nSimply run the following command (it will create the result directory if it doesn't exist yet):\n\n```\nstaticfiles -o files/files.go static/\n```\n\nI recommend putting it into a `Makefile` as follows:\n\n```\nfiles/files.go: static/*\n\tstaticfiles -o files/files.go static/\n```\n\nThe `staticfiles` command accept the following arguments:\n\n```\n--build-tags string\n      Build tags to write to the file\n-o string\n      File to write results to. (default \"staticfiles.go\")\n--package string\n      Package name of the resulting file. Defaults to name of the resulting file directory\n```\n\n## Local development mode\n\nWhile Staticfiles doesn't have a built-in local development mode, it does support build tags which makes implementing one very easy. Simply run `staticfiles` with `--build-tags=\"!dev\"` and add a file in the same directory that implements the same API, but with `//+build dev` at the that and using `http.FileServer` under the hood. You can find an example in `files/files_dev.go`. Once you have that set up you can simply do `go build --tags=\"dev\"` to compile the development version. In the way I set it up, you could even do `go build --tags=\"dev\" -ldflags=\"-X bou.ke/staticfiles/files.staticDir=$(pwd)/static\"` to set the static file directory to a specific path.\n\n## API\n\nThe resulting file will contain the following functions and variables:\n\n### `func ServeHTTP(http.ResponseWriter, *http.Request)`\n\n`ServeHTTP` will attempt to serve an embedded file, responding with gzip compression if the clients supports it and the embedded file is compressed.\n\n### `func Open(name string) (io.ReadCloser, error)`\n\n`Open` allows you to read an embedded file directly. It will return a decompressing `Reader` if the file is embedded in compressed format. You should close the `Reader` after you're done with it.\n\n### `func ModTime(name string) time.Time`\n\n`ModTime` returns the modification time of the original file. This can be useful for caching purposes.\n\n### `NotFound http.Handler`\n\n`NotFound` is used to respond to a request when no file was found that matches the request. It defaults to `http.NotFound`, but can be overwritten.\n\n### `Server http.Handler`\n\n`Server` is simply `ServeHTTP` but wrapped in `http.HandlerFunc` so it can be passed into `net/http` functions directly.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbouk%2Fstaticfiles","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbouk%2Fstaticfiles","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbouk%2Fstaticfiles/lists"}