https://github.com/pierods/embedder
Embedder is a function/command to embed resources in Go source files
https://github.com/pierods/embedder
asset binary-data embed go golang
Last synced: 24 days ago
JSON representation
Embedder is a function/command to embed resources in Go source files
- Host: GitHub
- URL: https://github.com/pierods/embedder
- Owner: pierods
- License: apache-2.0
- Created: 2017-07-10T10:33:25.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-07-10T14:10:34.000Z (over 8 years ago)
- Last Synced: 2024-06-20T00:35:40.361Z (over 1 year ago)
- Topics: asset, binary-data, embed, go, golang
- Language: Go
- Size: 7.81 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# embedder
[](https://opensource.org/licenses/Apache-2.0)
[](http://godoc.org/github.com/pierods/embedder)
[](https://goreportcard.com/report/github.com/pierods/embedder)
[](https://travis-ci.org/pierods/embedder)
Embedder is a function/command line utility to embed a binary or non-binary resource into a Go package.
## Usage
As a library:
```Go
hW := []byte("hello, world")
embedded, err := Embed("AssetVar", hW)
if err != nil {
t.Fatal(err)
}
embedded = append([]byte("package mypackage \n"), embedded...)
if err != nil {
...
}
ioutil.WriteFile("MyEmbeddedAsset.go", embedded, os.ModePerm)
...
```
As a command-line utility:
```Go
embed -package mypackage -var MyImageGif -asset myImage.gif > MyEmbeddedAsset.go
```
In go:generate:
```Go
//go:generate embed -package mypackage -var MyImageGif -asset myImage.gif -o MyEmbeddedAsset.go
```
## Installation:
```Go
go get github.com/pierods/embedder
cd %GOPATH/src/github.com/pierods/embedder/embed
go install
```
## Why not go-binddata, statik etc
go-bindata: 47 issues, compiles with Makefile
statik: it creates a statikFS fileserver - I don't need a fileserver
rice: it crates an HTTPBox - I don't need a box.
etc.
Embedder does one thing and does it well - embedding resources. You can then wrap the embedded resource in a file server or whatever.