A few weeks ago I wrote a GoLang web app and wanted to find a good place to host it. Given I work with the team that builds Azure Websites, it seemed only fitting to host it in Azure Websites. Turns out, it works great! However, there aren’t any resources available that walk you through the steps. Consequently, I wrote the following tutorial.

(Incidentally, if you want to start to use Go Language and run Windows you’ll want to review my post Easy Go Programming Setup for Windows.)

Is this the absolutely authority on running Go Language in Azure Websites? No, but it works. I plan to publish a few more articles on more complex scenarios in the future.

  1. Create your Azure Website in the Azure Portal. Without a doubt the easiest step.

  2. Download and unzip the Go executables. In the Azure Portal select your website blade and scroll down until you see the Console tile.

    Open Console on the Azure websites blade

    In the console to the right, type the following commands:

    curl -O


    You should see the following:


    Be patient with the console as these two operations may take a few moments. It’s purposefully simple.

    Note: I’m not sure why it returns Bad Request but so far it doesn’t seem to cause any issues.

  3. Create a server.go file in the wwwroot folder. This is a super simple Go file which will reply for any resource on the website.

    package main
    	import (
    	func handler(w http.ResponseWriter, r *http.Request) {
    	    fmt.Fprintf(w, "You just browsed page (if blank you're at the root): %s", r.URL.Path[1:])
    	func main() {
    	    http.HandleFunc("/", handler)
    	    http.ListenAndServe(":"+os.Getenv("HTTP\_PLATFORM\_PORT"), nil)

    As a convenience, feel free to use curl and download this directly from my public gist. Otherwise, you should consider using Kudu or git to get your files into your Azure Website.

    curl -L --output server.go

    Once downloaded, type type server.go to confirm you grabbed everything correctly.

  4. Create a Web.Config file in the wwwroot folder. We will use the httpPlatformHandler simpilar to running Tomcat in Azure Websites.

    <?xml version="1.0" encoding="UTF-8"?>
    	            <add name="httpplatformhandler" path="\*" verb="\*" modules="httpPlatformHandler" resourceType="Unspecified" />
    	        <httpPlatform processPath="d:\home\site\wwwroot\go\bin\go.exe" 
    	                      arguments="run d:\home\site\wwwroot\server.go" 
    	              <environmentVariable name="GOROOT" value="d:\home\site\wwwroot\go" />

    Again, you can use the following curl command to download the Web.Config file:

    curl -L --output Web.Config

That is it! You can now browse to your Azure Website and see it in action.

For now, try it out here:

Is there more we can do here? Absolutely, and I intend to cover some additional topics in future posts. However, for now, it feels good knowing that we can push our Go Language code to Azure Websites.

Special thanks to Ranjith Mukkai Ramachandra for his help and answering all my questions quickly and thoroughly!

comments powered by Disqus