如何将文件嵌入到 Go 二进制文件中 [英] How to embed files into Go binaries

查看:33
本文介绍了如何将文件嵌入到 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 二进制文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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