英文:
Golang: HTTP deployment under Windows
问题
Go语言提供了处理HTTP响应的处理程序。在命令提示符上启动一个Go程序来监听传入的HTTP请求非常简单。
在Windows Server机器上以后台方式运行这样的Go程序有哪些部署选项?例如,是否有一种标准方法可以创建一个在后台运行Go程序的Windows服务?
英文:
The Go language provides handlers for serving HTTP responses. It is easy enough to start up a Go program on the command prompt, that listens for incoming HTTP requests.
What are the deployment options for running such a Go program in the background on a Windows Server machine? For example, is there a standard method for creating a Windows Service that runs the Go program in the background?
答案1
得分: 14
有一个优秀的golang包kardianos/service,它可以让你在任何目标平台上创建一个服务。
正如你可以在这里看到的(页面是法语的,但有趣的是页面开头的代码示例),你可以很容易地通过命令行选项扩展你的程序,例如:
-
install 安装服务。
-
remove 移除服务。
-
run 简单地运行程序(不作为服务)。
-
start/stop 服务的启动/停止
英文:
There is an excellent golang package kardianos/service that will allow you to create a service whatever the platform you are targeting.
As you can see here (it is in french but what is interesting is the code sample at the begginning of the page), it is easy to extend your program with command line options such as :
- install install the service.
- remove remove the service.
- run simply run the program (not as a service).
- start/stop the service
答案2
得分: 1
- 使用NSSM(从任何可执行文件创建服务):
nssm install MyService d:\MyService.exe
... 其他内容 ...
英文:
> nssm install MyService d:\MyService.exe
- Use golang.org/x/sys/windows/svc package
... others ...
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论