I’m trying to run my Go application as a Windows service, but despite using svc.IsWindowsService()
(the example in https://github.com/golang/sys/blob/master/windows/svc/example/main.go), it still returns false when the application is started as a Windows service. How can I properly configure my Go application to run as a Windows service?
Thank you!
This is my code
func main() {
setupService()
}
func setupService() {
isWindowService, err := svc.IsWindowsService()
if err != nil {
log.Fatalf("failed to determine it is Windows service: %v", err)
}
log.Printf("isWindowService: %v", isWindowService)
if isWindowService {
service.RunService(utils.SVCName)
return
}
err = service.InstallService(utils.SVCName, "vcoa")
if err != nil {
log.Fatalf("failed to install the service: %v", err)
}
err = service.StartService(utils.SVCName)
if err != nil {
log.Fatalf("failed to start the service: %v", err)
}
}