将文本文件嵌入编译的可执行文件 [英] Embedding text file into compiled executable

查看:119
本文介绍了将文本文件嵌入编译的可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些我从Go程序中读取的文本文件。我想运送一个可执行文件,而不另外提供该文本文件。
如何将它嵌入到编译中?

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?

问题在于Windows和Linux。

The question is both for 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.

这篇关于将文本文件嵌入编译的可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆