如何将文件嵌入到 Go 二进制文件中

编程入门 行业动态 更新时间:2024-10-28 14:36:50
本文介绍了如何将文件嵌入到 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 二进制文件中

本文发布于:2023-11-03 07:59:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1554630.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何将   二进制文件   文件

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!