embed

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2020 License: MIT Imports: 0 Imported by: 0

README

embed

CI

embed is a tool for embedding static content in your Go application.

It provides three methods, listing embedded files and getting their content as []byte or string. If you need a io.Writer just wrap the []byte content in a bytes.NewBuffer.

The motivation for building yet another static file embedding tool for Go was that I was not satisified with any of the existing tools, they either had inconvenient APIs or did not support to include more than a single folder or file.

Please note that this tool, as well as most other static file embedding tools, will be redundant as soon as the proposal to add support for embedded files lands in go/cmd.

Usage

You can run the tool with go run github.com/klingtnet/embed/cmd/embed or by downloading a precompiled binary from the releases page.

$ ./embed
NAME:
   embed - A new cli application

USAGE:
   embed [global options] command [command options] [arguments...]

COMMANDS:
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --package value, -p value                    name of the package the generated Go file is associated to (default: "main")
   --destination value, --dest value, -d value  where to store the generated Go file (default: "embeds.go")
   --include value, -i value                    paths to embed, directories are stored recursively (can be used multiple times)
   --help, -h                                   show help (default: false)

Running embed --include assets --include views will create a file embeds.go (you can change the destination) that bundles all files from the assets and views directory. In your application you can then use embeds.File("assets/my-asset.png") to get the contents of an embedded file. For an example of such a generated file see internal/embeds.go.

golang-migrate driver

The package also provides a migration source driver for golang-migrate. For a usage example refer to examples/migrate/migrate.go.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Embed

type Embed interface {
	// Files returns an alphabetically sorted list of the embedded files.
	Files() []string
	// File returns the content of the file embedded as path.
	File(path string) []byte
	// FileString is a convenience function
	// that works like File but returns a string
	// instead of a byte slice.
	FileString(path string) string
}

Embed defines methods for retrieving embedded content.

Directories

Path Synopsis
cmd
examples
migrate Module

Jump to

Keyboard shortcuts

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