你如何在golang中设置应用程序图标? [英] How do you set the application icon in golang?

查看:512
本文介绍了你如何在golang中设置应用程序图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我如何给它一个图标?



似乎没有任何构建标记可以做到这一点,我知道golang不支持资源。 解决方案

您可以使用像 akavel / rsrc 这样的工具来生成嵌入了指定资源的.syso文件在 .rsrc 部分中,目标是在构建Win32可执行文件时由Go链接器使用。 a href =https://github.com/lxn/walk#create-manifest-testmanifest =noreferrer> lxn / walk 应用程序,它将其他元数据嵌入到其可执行文件中。

  rsrc [-manifest FILE.exe.manifest] [-ico FILE.ico [,FILE2.ico ...]] -o FILE.syso 

-ico =:comma-将.ico路径的分隔列表嵌入




这个不同将二进制数据嵌入到go程序中。

为此,请使用 jteeuwen / go-bindata
$ b


要访问资产数据,我们使用 Asset(字符串)[]字节




  data:=资产中的code>函数,它包含在生成的输出中。 (pub / style / foo.css)
如果len(数据)== 0 {
//资产未找到。
}

//使用资产数据


I've just created my first go application on Windows.

How do I give it an icon?

There doesn't seem to be any build flags to do this, and I know golang doesn't support resources.

解决方案

You can use a tool like akavel/rsrc in order to generate a .syso file with specified resources embedded in .rsrc section, aimed for consumption by Go linker when building Win32 excecutables.

See as an example the lxn/walk application, which embeds other metadata in its executable.

rsrc [-manifest FILE.exe.manifest] [-ico FILE.ico[,FILE2.ico...]] -o FILE.syso

-ico="": comma-separated list of paths to .ico files to embed


This differs from embedding binary data into a go program.
For that, use jteeuwen/go-bindata.

To access asset data, we use the Asset(string) []byte function which is included in the generated output.

data := Asset("pub/style/foo.css")
if len(data) == 0 {
    // Asset was not found.
}

// use asset data

这篇关于你如何在golang中设置应用程序图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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