Lately, I thought of trying my hands on the classic Ajax alongside Go language. The requirement is to write a simple web server which sends ‘current timestamp’ to the requester every second. I have written a small program to do exactly the same. The Ajax part is taken care by jquery.
In order to see it in action, one needs to run it “go run tick-tock.go”. When the program is running, it essentially becomes a tiny web server listening to requests at port ‘9999’.
Now all you need to do is fire up a browser and raise a request to the tick-tock server: http://localhost:9999/time
Go is awesome. Isn’t it?
// success callback, where 'position' holds the found coordinates.
// Instantiate a Google Map's LatLng object using the position coordinates.
initialLocation = new google.maps.LatLng(position.coords.latitude,
Now 'initialLocation' can be used to place a marker on the map or
other coordinates related stuff.
// error callback, where 'positionError' holds various error related
// attributes (see reference (ii) for details).
// log the error message
console.log("Geolocation service failed. MSG: " + positionError.message);
// Browser doesn't support Geolocation
console.log("Your browser doesn't support geolocation.");