esc: Files | Directories

Command esc

esc embeds files into go programs and provides http.FileSystem interfaces to them.

It adds all named files or files recursively under named directories at the path specified. The output file provides an http.FileSystem interface with zero dependencies on packages outside the standard library.


esc [flag] [name ...]

The flags are:

	output filename, defaults to stdout
	package name of output file, defaults to main
	strip given prefix from filenames
	regular expression for files to ignore
	regular expression for files to include
	Unix timestamp to override as modification time for all files
	unexport functions by prefixing them with esc, e.g. FS -> escFS
	do not compress files

Accessing Embedded Files

After producing an output file, the assets may be accessed with the FS() function, which takes a flag to use local assets instead (for local development).

FS(Must)?(Byte|String) returns an asset as a (byte slice|string). FSMust(Byte|String) panics if the asset is not found.

Go Generate

esc can be invoked by go generate:

//go:generate esc -o static.go -pkg server static


Embedded assets can be served with HTTP using the http.FileServer. Assuming you have a directory structure similar to the following:

├── main.go
└── static
    ├── css
    │   └── style.css
    └── index.html

Where main.go contains:

package main

import (

func main() {
	// FS() is created by esc and returns a http.Filesystem.
	http.Handle("/static/", http.FileServer(FS(false)))
	log.Fatal(http.ListenAndServe(":8080", nil))

1. Generate the embedded data:

esc -o static.go static

2. Start the server:

go run main.go static.go

3. Access http://localhost:8080/static/index.html to view the files.

Package Files

doc.go main.go


embedPackage embed implements all file embedding logic for

Package main imports 5 packages (graph). Updated 2020-04-28. Refresh now. Tools for package owners.