stringfs

command module
v0.0.0-...-b3b9b66 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 13, 2021 License: MIT Imports: 12 Imported by: 0

README

stringfs

Stringfs is a go package that encodes a net/http filesystem into a string.

⚠️This package is deprecated. You should use the embed package instead of this one. It is better in every way.

Usage

Run go get github.com/paulhammond/stringfs to install.

To use stringfs, first declare a variable in your source code:

var fileSystem http.FileSystem = http.Dir("./example/assets")

Then encode the contents of directory into a string using the stringfs command:

stringfs example/assets example/assets.go

Full documentation is available through godoc.

License

MIT license, see LICENSE.txt for details.

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
}

Directories

Path Synopsis
Example is an example of using stringfs.
Example is an example of using stringfs.
fs provides the implementation of stringfs.
fs provides the implementation of stringfs.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL