Skip to content


Folders and files

Last commit message
Last commit date

Latest commit



63 Commits

Repository files navigation

Package statics

Project status Build Status Go Report Card GoDoc License

Package statics embeds static files into your go applications. It provides helper methods and objects to retrieve embeded files and serve via http.

It has the following unique features:

  • Follows Symlinks! uses the symlinked file/directory name and path but the contents and other fileinfo of the original file.
  • Embeds static generation command for using go:generate in each static file for easy generation in production mode.
  • Handles multiple static go files, even inside of the same package.
  • Handles development (aka local files) vs production (aka static files) across packages.


	go get -u

Then import the statics package into your own code.

import ""

Usage and documentation

Please see for detailed usage docs.

NOTE: when specifying path or directory name in code always use "/", even for you windows users, the package handles any conversion to you local filesystem paths; Except for the AbsPkgPath variable in the config.

run statics -h to see the options/arguments


Embedding in Source Control

statics -i=assets -o=assets.go -pkg=main -group=Assets -ignore=\\.gitignore -init=true


//go:generate statics -i=assets -o=assets.go -pkg=main -group=Assets -ignore=\.gitignore

package main

import ""

// newStaticAssets initializes a new *static.Files instance for use
func newStaticAssets(config *static.Config) (*static.Files, error) {

	return static.New(config, &static.DirFile{})

when using arg init=true statics package generates a minimal configuration with no files embeded; you can then add it to source control, ignore the file locally using git update-index --assume-unchanged [filename(s)] and then when ready for generation just run go generate from the project root and the files will get embedded ready for compilation.

Be sure to check out this packages best buddy to help get everything generated and ready for compilation.

Example Usage

// generated via command: 
// statics -i=assets -o=assets.go -pkg=main -group=Assets -ignore=//.gitignore

gopath := getGopath() // retrieved from environment variable
pkgPath := "/src/"

// get absolute directory path of the -i arguments parent directory + any prefix 
// removed, used when UseStaticFiles=false this is so even when referencing this 
// package from another project and your PWD is not for this package anymore the 
// file paths will still work.
pkg := goapth + pkgPath

config := &static.Config{
	UseStaticFiles: true,
	AbsPkgPath:     pkg,

// NOTE: Assets in the function name below is the group in the generation command
assets, err := newStaticAssets(config)
if err != nil {

// when using http
http.Handle("/assets", http.FileServer(assets.FS()))

// other methods for direct access

Package Versioning

I'm jumping on the vendoring bandwagon, you should vendor this package as I will not be creating different version with like allot of my other libraries.

Why? because my time is spread pretty thin maintaining all of the libraries I have + LIFE, it is so freeing not to worry about it and will help me keep pouring out bigger and better things for you the community.


Distributed under MIT License, please see license file in code for more details.


📁 Embeds static resources into go files for single binary compilation + works with http.FileSystem + symlinks







No packages published