Documentation
¶
Overview ¶
Stringfs encodes a net/http FileSystem into a string.
Most web applications require a number of static assets such as images, CSS stylesheets etc. Stringfs provides a way to compile those assets into a single application binary for easier deployment.
Usage:
stringfs [flags] directory outputfile
Stringfs takes a directory and an output file. It encodes all files within the directory into a string in specified output source file.
The flags are:
-var
The variable the encoded string will be assigned to. Defaults to
"fileSystem"
-pkg
The package this file will be part of. If not specified stringfs will
autodetect the package name by checking other files in the same
directory.
The file created by stringfs does not declare the variable, it just assigns a value. You are expected to declare the variable yourself in another file, giving you control over initialization.
A typical usage is to declare the variable with a fallback value. This allows you to remove the generated file during development, avoiding an extra compilation step. For example:
var assets http.FileSystem = http.Dir("./assets")
Alternatively you can initialize the variable and later check for the nil value. For example:
// at the top level
var assets http.FileSystem
// inside a function
if assets == nil {
// working with precompiled assets
} else {
// no precompiled assets
}