How do you set the application icon in golang?

前端 未结 5 887
抹茶落季
抹茶落季 2021-01-30 09:14

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

5条回答
  •  再見小時候
    2021-01-30 09:48

    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
    

提交回复
热议问题