{"repo":"rakyll/statik","free":true,"listed":false,"github":"https://github.com/rakyll/statik","clone":"git clone https://github.com/rakyll/statik.git","description":"Embed files into a Go executable","language":"Go","stars":3825,"topics":["static","files","golang","go","http","http-server"],"license":"Apache-2.0","category":"networking-infra","readme_excerpt":"statik statik allows you to embed a directory of static files into your Go binary to be later served from an http.FileSystem. Is 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. Usage Install the command line tool first. go install github.com/rakyll/statik@latest statik 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. The command below will walk on the public path and generate a package called statik under the current working directory. $ statik -src=/path/to/your/project/public The command below will filter only files on listed extensions. $ statik -include= .jpg, .txt, .html, .css, .js In your program, all your need to do is to import the generated package, initialize a new statik file system and serve. go import ( \"github.com/rakyll/statik/fs\" \"./statik\" // TODO: Replace with the absolute import path ) // ... statikFS, err := fs.New() if err != nil { log.Fatal(err) } // Serve the contents over HTTP. http.Handle(\"/public/\", http.StripPrefix(\"/public/\", http.FileServer(statikFS))) http.ListenAndServe(\":808","default_branch":null,"files":null,"tree":[],"storefront":"/r/rakyll","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/rakyll/statik/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}