Tuesday, November 13, 2012

Serving Go using FastCGI on Windows Azure

One of the cooler features of Windows Azure is that you can spin up Linux virtual machines on it and run apps written in the language of your choice.

These are the steps I followed to create a Linux VM on Windows Azure, install nginx and Go on it and serve up a "Hello World" app using FastCGI.

First, I signed up a 3-month trial account on Windows Azure - you will need a Microsoft Account for this.

Next, I created a new Virtual Machine using New -> Compute -> Virtual Machine -> From Gallery.



I selected Ubuntu Server 12.04.1 -



I gave the new VM a name - GoMachine, selected a username and password and hit Next -


I selected VM type as Standalone and the DNS name as gopher.cloudapp.net -



Choose Availability Set as None -



Once the VM was provisioned, I SSH'd into it using PuTTy using the credentials I had set earlier -


I installed Go using the command - sudo apt-get install golang-go.

I installed nginx using the command - sudo apt-get install nginx.

Next, I created a directory called fcgi in which I created a file - fcgi.go -

and compiled it using go build fcgi.go.

I edited the file /etc/nginx/sites-available/default to allow it to serve FastCGI and pointed it to 127.0.0.1:9999 where the fcgi app will listen. The server will also take requests directed to http://gopher.cloudapp.net.

I started the fcgi application using ~/fcgi/fcgi& to run it in the background. I also restarted nginx using sudo service nginx restart for the new configuration  to take effect.

To test the app, I typed curl http://localhost/hello. It worked. However, curl http://gopher.cloudapp.net/hello didn't. To make this work, I had to create a new 'endpoint' for the VM in the dashboard -


I clicked on Add Endpoint, and created a new TCP endpoint on Port 80 -




Now, the web app is accessible from the outside world.


Update: - My 3 month trial has expired. So the above URL is not accessible any longer.


Wednesday, November 7, 2012

Querying Sharepoint on Office365 with Go

This code snippet shows how to query Sharepoint hosted on Microsoft's Office365 service. This was inspired by Luc Stakenborg's excellent Node-Sharepoint library.


Update: This no longer works. Office365 has now been upgraded to use Sharepoint 2013, which supports OAuth-based authentication. More details here - http://msdn.microsoft.com/en-us/library/fp142384.aspx

Thursday, November 1, 2012

Knockout.js – Creating a table with a cell conditionally spanning multiple rows.

Creating HTML tables with conditional elements is a common scenario when creating user interfaces. This fiddle demonstrates how to create a table with a cell that conditionally spans multiple rows using Knockout.js.