Giter Site home page Giter Site logo

rhaseven7h / goembed Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 9 KB

GoEmbed generates a file that you may include in your project to include a file's content as code, embedded within the binary.

License: Creative Commons Attribution Share Alike 4.0 International

Go 100.00%
go golang golang-application golang-tools embed generate gogenerate go-generate embedfiles embed-files

goembed's Introduction

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.

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.

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:

package data

import (
	"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: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.

 Creative Commons Attribution-ShareAlike 4.0 International License.

goembed's People

Contributors

rhaseven7h avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.