Golang:在Windows下进行HTTP部署

huangapple go评论69阅读模式
英文:

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

  1. 使用NSSM(从任何可执行文件创建服务):

nssm install MyService d:\MyService.exe

  1. 使用golang.org/x/sys/windows/svc包。

... 其他内容 ...

英文:
  1. Use NSSM (create service from any executable)

> nssm install MyService d:\MyService.exe

  1. Use golang.org/x/sys/windows/svc package

... others ...

huangapple
  • 本文由 发表于 2014年6月23日 11:02:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/24357887.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定