esc alternatives and similar packages
Based on the "Resource Embedding" category.
Alternatively, view esc alternatives based on common mentions on social networks and blogs.
-
go.rice
go.rice is a Go package that makes working with resources such as html,js,css,images,templates, etc very easy. -
vfsgen
Takes an input http.FileSystem (likely at go generate time) and generates Go code that statically implements it. -
fileb0x
a better customizable tool to embed files in go; also update embedded files remotely without restarting the server -
go-bindata
A small utility which generates Go code from any file. Useful for embedding binary data in a Go program. -
go-resources
Unfancy resources embedding for Go with out of box http.FileSystem support. -
statics
:file_folder: Embeds static resources into go files for single binary compilation + works with http.FileSystem + symlinks -
go-embed
Generates go code to embed resource files into your library or executable -
templify
A tool to be used with 'go generate' to embed external template files into Go code. -
rebed
Recreates directory and files from embedded filesystem using Go 1.16 embed.FS type. -
mule
mule is a tool to be used with 'go generate' to embed external resources files into Go code.
Access the most powerful time series database as a service
Do you think we are missing an alternative of esc or a related project?
Popular Comparisons
README
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.
Installation
go get -u github.com/mjibson/esc
Usage
esc [flag] [name ...]
The flags are:
-o=""
output filename, defaults to stdout
-pkg="main"
package name of output file, defaults to main
-prefix=""
strip given prefix from filenames
-ignore=""
regular expression for files to ignore
-include=""
regular expression for files to include
-modtime=""
Unix timestamp to override as modification time for all files
-private
unexport functions by prefixing them with esc, e.g. FS -> escFS
-no-compress
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).
- (_esc)?FS(Must)?(Byte|String) returns an asset as a (byte slice|string).
- (_esc)?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
Example
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 (
"log"
"net/http"
)
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))
}
- Generate the embedded data:
esc -o static.go static
- Start the server:
go run main.go static.go
- Access http://localhost:8080/static/index.html to view the files.
You can see worked example in [example](example) dir
just run it as
go run example/main.go example/static.go