CLI app to embed binary file data into Go files
Switch branches/tags
Nothing to show
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci Update CircleCI configuration Oct 6, 2018
cmd/lodge Remove copy/pasted name from another project. Nov 5, 2018
.gitignore Add dist, run, and test to .gitignore Mar 23, 2018
LICENSE Initial commit Mar 22, 2018
Makefile Simplify Makefile Oct 6, 2018
README.md Update README.md Oct 18, 2018
go.mod go mod init Sep 12, 2018
lodge.go Add support for -ignore flag (#7) Jul 7, 2018
template.go Fix imports when not gzipping May 5, 2018

README.md

lodge

CircleCI

CLI app to embed binary file data into Go files.

Installation

To get the most up to date binaries, check the releases for the pre-built binary for your system.

You can also go get to install from source.

go get -u github.com/tombell/lodge/cmd/lodge

On macOS you can use Homebrew to install.

brew tap tombell/formulae && brew install tombell/formulae/lodge

Usage

Use the -h/--help flag to see all the available flags when running lodge.

Running lodge without any arguments will print out the usage instructions.

lodge

lodge expects at minimum some input directories to read the files from to embed.

lodge ./path/to/templates/

You are able to pass as many directories as you wish. All subdirectories will be included by default.

If you would like to strip of a path prefix, use the -prefix flag with the path prefix you would like stripped.

Without the -prefix flag, the file paths will all be prefixed.

lodge ./path/to/templates/
# assets["./path/to/templates/index.html"]
# assets["./path/to/templates/image.png"]
# assets["./path/to/templates/footer.html"]

When specifying the -prefix flag, the path prefix is stripped.

lodge -prefix=./path/to/ ./path/to/templates/
# assets["templates/index.html"]
# assets["templates/image.png"]
# assets["templates/footer.html"]

By default the package of the generated output file is main, use the -pkg flag to override the package.

lodge -pkg assets ./path/to/templates/

If you would like to compress the file data using GZIP, you can use the -gzip flag.

lodge -gzip ./path/to/templates/

By default the file name of the output file is files.go, use the -output flag to override the file name.

lodge -output ./templates.go ./path/to/templates/

Use the -build flag to include build tags.

lodge -build linux,darwin ./path/to/templates/

Once you've generated your file, you will be able to include it in your Go projects.

To read a file from the embedded data, access the Assets map, where the file path is the key. This will return the uncompressed bytes if the data was compressed with GZIP.

data, err := GetAsset("./path/to/templates/index.html)
if err != nil {
  // failed to get the file data
}

A function is provided called GetGzippedAsset if the file data has been compressed. This function will return the compressed bytes.

data, err := GetGzippedAsset("./path/to/templates/index.html")
if err != nil {
  // failed to get the file data
}

That's all there is to it!