Active Cloud DB - Go Edition
One of the big problems I have as a programmer is that I don't have great UI skills, so whenever I have to make a UI for an app, it tends to look like crap. Lo and behold, to my amazement, that Twitter has taken a huge step towards fixing this problem for me with Bootstrap. Who would have guessed that all I needed was a single CSS file to make my web apps look pretty?
Having seen what Bootstrap can do (and if you haven't looked at that link, go check it out), I decided to take on a small project to give it a test drive. With that, let's talk about Active Cloud DB - Go Edition!
Last year I put together Active Cloud DB, a REST interface to any database that supports the Google App Engine Datastore API. That means that your client (in whatever language you want) can make REST calls to save and retrieve data without having to know how the underlying database works or how to optimize it. Naturally you may assume that the Google App Engine Datastore API is only supported by Google App Engine, and therefore you'd only be able to utilize a single database. But you'd be wrong! Since AppScale implements the Datastore API for all its databases, you can now save and retrieve data to any of the nearly dozen databases it supports. For example, you can save data from your Haskell application to Active Cloud DB and have Cassandra running via AppScale, which I think is pretty cool.
Active Cloud DB is written in Python, and I've been itching for a project to undertake with the sexy new Go App Engine runtime. It couldn't be better reflected in the name - Active Cloud DB - Go Edition! Here's how it all meshes together. All the Datastore communication is done in Go, so querying is done in the usual manner:
func query(w http.ResponseWriter, r *http.Request) {
c := appengine.NewContext(r)
q := datastore.NewQuery("Entity")
result := map[string] string {}
for t := q.Run(c); ; {
var entity Entity
key, err := t.Next(&entity)
if err == datastore.Done {
break
}
if err != nil {
result["error"] = fmt.Sprintf("%s", err)
}
keyString := fmt.Sprintf("%s", key)
result[keyString] = entity.Value
}
fmt.Fprintf(w, "%s", mapToJson(result))
}As you can see from the above snippet, all the Go methods that we have output JSON that AJAX requests can easily consume. We have a small set of Go methods (put/get/delete/query) to keep the interface nice and simple. The app is simple enough to need only a single HTML page, and Bootstrap makes it look damn nice (if I do say so myself). It's got some nice pretty buttons, flash messages, and other things you've seen for years now but look just flawless with Bootstrap. To wrap it all up, there's AJAX that intercepts most of the button clicks and talks to the Go backend. Here's a screenshot of Active Cloud DB in action:
The Python version is still a bit ahead as far as feature support goes - it has caching optimizations from our CloudComp paper that speed up most of the operations via the Memcache API. We'll get to implementing those soon, and that will necessitate a follow-up post. In the meanwhile, go get coding with Go, App Engine, and Bootstrap!
Go + AppScale
I just got back from Google I/O last week and after hearing about the cool new Go support in App Engine, I set out to get Go working over our implementation in of App Engine, namely AppScale. After a bit of hacking I got it working - here's a screenshot of the go-mandlebrot demo:

Living up to their promise as being super cool and open-source, the Go App Engine code is available for people wanting to hack around with it - of course that's me! But I wasn't able to compile the Go App Engine SDK out of the box. Thankfully, it turned out to be pretty straightforward, so here's what to do if you want to do it (or if you're a future version of me who has forgotten how to do it and needs to remember). Enjoy!
Compiling the Go App Engine SDK in Three Easy Steps, each with sub-steps:
Step 1: Install Go
Step 1.1: Install Go's language prerequisites
sudo apt-get install bison ed gawk gcc libc6-dev make sudo apt-get install python-setuptools python-dev build-essential
Step 1.2: Install Mercurial (skip if you can run 'hg')
sudo easy_install mercurial
Step 1.3: Actually install go
hg clone -u release https://go.googlecode.com/hg/ go cd go/src ./all.bash
Step 1.4: Move Go out of your home directory
cd ../.. sudo mv go /usr/local/ export PATH=$PATH:/usr/local/go/bin export GOROOT=/usr/local/go
Step 2: Install Go's Protocol Buffer Bindings
Step 2.1: Install Protocol Buffers
wget http://protobuf.googlecode.com/files/protobuf-2.4.1.tar.gz tar zxvf protobuf-2.4.1.tar.gz cd protobuf-2.4.1 ./configure make make check make install cd .. rm -rfv protobuf-2.4.1 protobuf-2.4.1.tar.gz
Step 2.2: Install the Go Protocol Buffer Library and Protocol Compiler Plugin
goinstall goprotobuf.googlecode.com/hg/proto cd $GOROOT/src/pkg/goprotobuf.googlecode.com/hg/compiler make install
Step 3: Actually compile the Go App Engine SDK
Step 3.1: Get the Go App Engine SDK Source
hg clone https://appengine-go.googlecode.com/hg/ appengine-go
Step 3.2: Compile it
cd appengine-go make
And that's it! It should compile without problems, and now you have the ability to mess around with your very own Go App Engine SDK! I'm not exactly sure what you'd want to do with it, but I sure know what I do! Stay tuned for more updates from the wacky world of the cloud, now with 100% more Go!
