This code just shows how to build and package a Go web server (e.g.
a web app) that runs as a Windows service and will also compile and
run on non-Windows systems.
Building for Windows
Running go build, or if not on Windows, GOOS=windows go build
should produce a working testserver.exe. Then on Windows run
build.bat <version>, e.g. build.bat 1.0.0 to produce an MSI.
You need the WiX Toolset as well as
Microsoft’s mc, rc, and link. The paths for those on my machine
are hard set in build.bat. Edit to taste.
If you adapt this code for your own project, don’t forget to change
the UpgradeCode GUID in installer.wxs.
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
“Software”), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject
to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.