简体   繁体   English

Golang:Windows下的HTTP部署

[英]Golang: HTTP deployment under Windows

The Go language provides handlers for serving HTTP responses. Go语言提供用于提供HTTP响应的处理程序。 It is easy enough to start up a Go program on the command prompt, that listens for incoming HTTP requests. 在命令提示符下启动Go程序很容易,它会侦听传入的HTTP请求。

What are the deployment options for running such a Go program in the background on a Windows Server machine? 在Windows Server计算机上在后台运行这样的Go程序有哪些部署选项? For example, is there a standard method for creating a Windows Service that runs the Go program in the background? 例如,是否有一种标准方法用于创建在后台运行Go程序的Windows服务?

There is an excellent golang package kardianos/service that will allow you to create a service whatever the platform you are targeting. 有一个很好的golang包kardianos / service ,它允许您创建一个服务,无论您的目标是什么平台。

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 启动/停止服务
  1. Use NSSM (create service from any executable) 使用NSSM (从任何可执行文件创建服务)

nssm install MyService d:\\MyService.exe

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

... others ... ... 其他 ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM