I’m stumped again. The docs seem pretty clear on this.
https://golang.org/pkg/go/build/
factorio_server_linux.go
// +build linux
package main
// Stubs for windows-only functions
func sendCtrlCToPid(pid int) {
}
func setCtrlHandlingIsDisabledForThisProcess(disabled bool) {
}
factorio_server_windows.go
// +build windows
package main
import (
"log"
"syscall"
)
func sendCtrlCToPid(pid int) {
d, e := syscall.LoadDLL("kernel32.dll")
if e != nil {
log.Fatalf("LoadDLL: %v\n", e)
}
p, e := d.FindProc("GenerateConsoleCtrlEvent")
if e != nil {
log.Fatalf("FindProc: %v\n", e)
}
r, _, e := p.Call(uintptr(syscall.CTRL_C_EVENT), uintptr(pid))
if r == 0 {
log.Fatalf("GenerateConsoleCtrlEvent: %v\n", e)
}
}
func setCtrlHandlingIsDisabledForThisProcess(disabled bool) {
disabledInt := 0
if(disabled){
disabledInt = 1
}
d, e := syscall.LoadDLL("kernel32.dll")
if e != nil {
log.Fatalf("LoadDLL: %v\n", e)
}
p, e := d.FindProc("SetConsoleCtrlHandler")
if e != nil {
log.Fatalf("FindProc: %v\n", e)
}
r, _, e := p.Call(uintptr(0), uintptr(disabledInt))
if r == 0 {
log.Fatalf("SetConsoleCtrlHandler: %v\n", e)
}
}
build commands:
GOOS=linux GOARCH=amd64 go build -o factorio-server-manager/factorio-server-manager src/*
GOOS=windows GOARCH=amd64 go build -o factorio-server-manager/factorio-server-manager src/*
This is on a brand-new Ubuntu 16.04 VM. I already wiped my golang-go install once, when I realized it was using 1.6, and reinstalled with 1.8, per https://github.com/golang/go/wiki/Ubuntu
The build errors I’m getting indicate that it’s definitely trying to build for linux and windows, respectively, as I get an “undefined” error for syscall.LoadDLL only when building for linux. However, regardless of the GOOS setting, both of the above files are being compiled, and I’m getting “redeclared” errors. I can even switch both of them to // +build ignore
and they still end up attempting to build.
Also, just tried removing carriage returns.