{"id":13413730,"url":"https://github.com/rakyll/statik","last_synced_at":"2025-05-13T00:08:57.114Z","repository":{"id":13818427,"uuid":"16514887","full_name":"rakyll/statik","owner":"rakyll","description":"Embed files into a Go executable","archived":false,"fork":false,"pushed_at":"2023-10-18T01:18:28.000Z","size":313,"stargazers_count":3790,"open_issues_count":39,"forks_count":225,"subscribers_count":49,"default_branch":"master","last_synced_at":"2025-05-13T00:08:49.900Z","etag":null,"topics":["files","go","golang","http","http-server","static"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rakyll.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-02-04T14:54:51.000Z","updated_at":"2025-05-08T11:00:40.000Z","dependencies_parsed_at":"2024-05-05T03:42:53.584Z","dependency_job_id":null,"html_url":"https://github.com/rakyll/statik","commit_stats":{"total_commits":94,"total_committers":29,"mean_commits":"3.2413793103448274","dds":0.5319148936170213,"last_synced_commit":"e5988123cababc33df1352cba7df8535f1337326"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rakyll%2Fstatik","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rakyll%2Fstatik/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rakyll%2Fstatik/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rakyll%2Fstatik/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rakyll","download_url":"https://codeload.github.com/rakyll/statik/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253843215,"owners_count":21972873,"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":["files","go","golang","http","http-server","static"],"created_at":"2024-07-30T20:01:47.611Z","updated_at":"2025-05-13T00:08:57.083Z","avatar_url":"https://github.com/rakyll.png","language":"Go","funding_links":[],"categories":["HarmonyOS","Resource Embedding","开源类库","Go","Go (134)","嵌入的资源","Repositories","资源嵌入","\u003cspan id=\"资源嵌入-resource-embedding\"\u003e资源嵌入 Resource Embedding\u003c/span\u003e","Relational Databases","資源嵌入"],"sub_categories":["Windows Manager","HTTP Clients","构建编译","HTTP客户端","查询语","Advanced Console UIs","\u003cspan id=\"高级控制台用户界面-advanced-console-uis\"\u003e高级控制台用户界面 Advanced Console UIs\u003c/span\u003e","交流","高級控制台界面","高级控制台界面"],"readme":"# statik\n\n[![Build Status](https://travis-ci.org/rakyll/statik.svg?branch=master)](https://travis-ci.org/rakyll/statik)\n\nstatik allows you to embed a directory of static files into your Go binary to be later served from an http.FileSystem.\n\nIs this a crazy idea? No, not necessarily. If you're building a tool that has a Web component, you typically want to serve some images, CSS and JavaScript. You like the comfort of distributing a single binary, so you don't want to mess with deploying them elsewhere. If your static files are not large in size and will be browsed by a few people, statik is a solution you are looking for.\n\n## Usage\n\nInstall the command line tool first.\n\n\tgo get github.com/rakyll/statik\n\nstatik is a tiny program that reads a directory and generates a source file that contains its contents. The generated source file registers the directory contents to be used by statik file system.\n\nThe command below will walk on the public path and generate a package called `statik` under the current working directory.\n\n    $ statik -src=/path/to/your/project/public\n\nThe command below will filter only files on listed extensions.\n\n    $ statik -include=*.jpg,*.txt,*.html,*.css,*.js\n\nIn your program, all your need to do is to import the generated package, initialize a new statik file system and serve.\n\n~~~ go\nimport (\n  \"github.com/rakyll/statik/fs\"\n\n  _ \"./statik\" // TODO: Replace with the absolute import path\n)\n\n  // ...\n\n  statikFS, err := fs.New()\n  if err != nil {\n    log.Fatal(err)\n  }\n  \n  // Serve the contents over HTTP.\n  http.Handle(\"/public/\", http.StripPrefix(\"/public/\", http.FileServer(statikFS)))\n  http.ListenAndServe(\":8080\", nil)\n~~~\n\nVisit http://localhost:8080/public/path/to/file to see your file.\n\nYou can also read the content of a single file:\n\n~~~ go\nimport (\n  \"github.com/rakyll/statik/fs\"\n\n  _ \"./statik\" // TODO: Replace with the absolute import path\n)\n\n  // ...\n\n  statikFS, err := fs.New()\n  if err != nil {\n    log.Fatal(err)\n  }\n  \n  // Access individual files by their paths.\n  r, err := statikFS.Open(\"/hello.txt\")\n  if err != nil {\n    log.Fatal(err)\n  }    \n  defer r.Close()\n  contents, err := ioutil.ReadAll(r)\n  if err != nil {\n    log.Fatal(err)\n  }\n\n  fmt.Println(string(contents))\n~~~\n\nThere is also a working example under [example](https://github.com/rakyll/statik/tree/master/example) directory, follow the instructions to build and run it.\n\nNote: The idea and the implementation are hijacked from [camlistore](http://camlistore.org/). I decided to decouple it from its codebase due to the fact I'm actively in need of a similar solution for many of my projects.\n\n## Deterministic output\n\nBy default, statik includes the \"last modified\" (mtime) time on files that it packs. This allows an HTTP FileServer to present the correct file modification times to clients.\n\nHowever, if you have a continuous integration task that checks that your checked-in static files in a git repository match the code that is generated on your CI system, you'll run into a problem: The mtime on the git checkout does not match what you have locally, causing tests to fail.\n\nYou can fix the test in one of two ways:\n\n1. In CI, manually set the mtime on the freshly checked out tree: [here's a stackoverflow answer](https://stackoverflow.com/a/22638823/93405) that provides a shell command to do that; or,\n2. Instruct statik not to store the \"last modified\" time.\n\nTo ignore the last modified time, use the `-m` to statik, like so:\n\n    $ statik -m -include=*.jpg,*.txt,*.html,*.css,*.js\n\nNote that this will cause http.FileServer to consider the file to always have changed \u0026 serve it with a \"Last-Modified\" of the time of the request.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frakyll%2Fstatik","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frakyll%2Fstatik","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frakyll%2Fstatik/lists"}