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?
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.
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.
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.
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:
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 :
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With