Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Golang: HTTP deployment under Windows

Tags:

http

windows

go

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?

like image 780
spindles Avatar asked Jun 23 '14 03:06

spindles


People also ask

How to install Golang on Windows?

Let’s start installing GoLang on Windows. 1. Download go for Windows. First, go to golang.org and click on “ Download Go “. It will lead to the download page. There you will have to select the msi installer for windows. Go download for Windows amd64. 2. Install go from .msi file.

How do I enable HTTP/2 in Golang?

To enable HTTP/2 for more complex configurations, to use lower-level HTTP/2 features, or to use a newer version of Go's http2 package, import "golang.org/x/net/http2" directly and use its ConfigureTransport and/or ConfigureServer functions.

How do I disable HTTP/2 on https in go?

Starting with Go 1.6, the http package has transparent support for the HTTP/2 protocol when using HTTPS. Programs that must disable HTTP/2 can do so by setting Transport.TLSNextProto (for clients) or Server.TLSNextProto (for servers) to a non-nil, empty map.

What is package HTTP and how do I use it?

Package http provides HTTP client and server implementations. Get, Head, Post, and PostForm make HTTP (or HTTPS) requests: The client must close the response body when finished with it:


1 Answers

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
like image 104
Benjamin BALET Avatar answered Oct 14 '22 13:10

Benjamin BALET