本文介绍了如何将文件嵌入到 Go 二进制文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些从 Go 程序中读取的文本文件.我想发布一个可执行文件,而不额外提供该文本文件.如何将其嵌入到 Windows 和 Linux 上的编译中?
I have some text file that I read from my Go program. I'd like to ship a single executable, without supplying that text file additionally. How do I embed it into compilation on Windows and Linux?
推荐答案使用 go-bindata.来自自述文件:
Use go-bindata. From the README:
此工具可将任何文件转换为可管理的 Go 源代码.对...有用将二进制数据嵌入到 go 程序中.文件数据是可选的gzip 在转换为原始字节切片之前进行压缩.
This tool converts any file into managable Go source code. Useful for embedding binary data into a go program. The file data is optionally gzip compressed before being converted to a raw byte slice.
更多推荐
如何将文件嵌入到 Go 二进制文件中
发布评论