Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rhaseven7h/goembed
GoEmbed generates a file that you may include in your project to include a file's content as code, embedded within the binary.
https://github.com/rhaseven7h/goembed
embed embed-files embedfiles generate go go-generate gogenerate golang golang-application golang-tools
Last synced: about 1 month ago
JSON representation
GoEmbed generates a file that you may include in your project to include a file's content as code, embedded within the binary.
- Host: GitHub
- URL: https://github.com/rhaseven7h/goembed
- Owner: rhaseven7h
- License: cc-by-sa-4.0
- Created: 2021-05-25T20:25:58.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-05-25T23:01:55.000Z (over 3 years ago)
- Last Synced: 2024-06-20T13:28:36.215Z (6 months ago)
- Topics: embed, embed-files, embedfiles, generate, go, go-generate, gogenerate, golang, golang-application, golang-tools
- Language: Go
- Homepage:
- Size: 8.79 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Go Embed Generator
## Summary
`goembed` generates a file that you may include in your project to include a file's content as code, embedded within the
binary.## Installation
You can use `go` tool to install it to you Go home (`$HOME/go/bin`) as `goembed` binary.
```shell
go install github.com/rhaseven7h/goembed@latest
```## Usage
You must specify the package name for the generated file, the output path and/or file name, the variable name for the
generated data, and finally, the input file.```shell
goembed \
-package mypackagename \
-output embeddedfiles/dataone.go \
-variable MyData \
my_input_file.txt
```You may specify `-` for both input and out files, which will use standard input and standard output respectively.
## Output
An example output for the above command would be the following:
```go
package dataimport (
"encoding/base64"
)var InitData []byte
func init() {
InitData, _ = base64.StdEncoding.DecodeString(
"" +
"ZnVuY3Rpb24gZ3ZtKCkgewogIE9VVFBVVD0kKHNndm0gIiRAIikKICBFWElUX0NP" +
"REU9JD8KICBpZiBbICRFWElUX0NPREUgLW5lIDEgXTsgdGhlbgogICAgZWNobyAk" +
"T1VUUFVUCiAgICByZXR1cm4KICBmaQogIGV2YWwgIiR7T1VUUFVUfSIKfQo=" +
"",
)
}
```With this, you may import the `data` package, and use the `data.InitData`
variable which will contain the original input contents in a `[]byte` slice.## Go Generate
You may use this tool with Go Generate functionality by adding a line as follows to your source code:
```go
//go:generate goembed -package pkgname -output data/input.go -variable MyData my_input_file.txt
```## Copyright
This work is licensed under
a [Creative Commons Attribution-ShareAlike 4.0 International License](http://creativecommons.org/licenses/by-sa/4.0/).![ Creative Commons Attribution-ShareAlike 4.0 International License.](https://i.creativecommons.org/l/by-sa/4.0/88x31.png)