winres
Package winres provides functions for embedding resources in a Windows executable built with Go.
Most often, you'll want to embed an application icon, a manifest, and "version information", which is what you can see
in the Details tab of file properties.
Command line tool
If you are looking for a command line tool, please head to go-winres.
Alternatives
This project is similar to akavel/rsrc
and josephspurrier/goversioninfo.
Limitations
This is not a real resource compiler, which means it won't help you embed these UI definitions:
ACCELERATORS
DIALOGEX
MENUEX
POPUP
If you ever need them, which is unlikely, use one of those tools instead:
rc.exe
and cvtres.exe
from Visual Studiowindres
from GNU Binary Utilitiesllvm-rc
and llvm-cvtres
from LLVM tools
See Resource Compiler for more information.
Usage
To embed resources, you need an .rsrc
section in your executable. Winres provides functions to compile this .rsrc
section into a COFF object file.
Put this file in your project directory, name it "something.syso" or, preferably,
"something_windows_amd64.syso", and you're done :
the go build
command will detect it and automatically use it.
You should have a look at the command line tool to try it. Using the library
gives you more control, though.
Here is a quick example:
package main
import (
"io/ioutil"
"os"
"github.com/tc-hib/winres"
)
func main() {
rs := winres.ResourceSet{}
cursorData, _ := ioutil.ReadFile("cursor.cur")
rs.Set(winres.RT_CURSOR, winres.ID(1), 0, cursorData)
rs.Set(winres.Name("CUSTOM"), winres.Name("COOLDATA"), 0x409, []byte("Hello World"))
rs.Set(winres.Name("CUSTOM"), winres.Name("COOLDATA"), 0x40C, []byte("Bonjour Monde"))
out, _ := os.Create("rsrc_windows_amd64.syso")
rs.WriteObject(out, winres.ArchAMD64)
}
Thanks
Many thanks to akavel for his help.
This project uses these very helpful libs: