A Swift backed Pastebin in Go

tl;dr

If you're looking for an OpenStack Swift based pastebin with fancy syntax highlighting written by someone that knows nothing about Go (and I who isn't?), I have the perfect project for you. It's called cfpaste.

--

I'm heading out to the first Go language conference next week, and before doing so, I figured I should do something fun with it. So, I wrote a little Pastebin app that's backed by Rackspace CloudFiles and uses Go and Martini

The original version was actually using Python and Flask, but porting it to Go was a sinch. Martini is definitely nice to work with and keeps it simple. It has some nice builtins like this pattern for making resources like a memcache or swift connection pool accessible to functions:

//martini looks for a HOST and PORT env var to determine what to listen on
m := martini.Classic()

cf := swift.Connection{
    UserName: username,
    ApiKey:   apikey,
    AuthUrl:  authurl,
    Region:   region,
    Internal: internal,
}
// Authenticate
err := cf.Authenticate()
PanicIf(err)
m.Map(&cf)

mc := memcache.New("127.0.0.1:11211")
m.Map(mc)

See where I threw the memcache instance in m.Map(mc). You can use this later like so:

func GetPaste(params martini.Params, ren render.Render, r *http.Request, cf *swift.Connection, mc *memcache.Client) {
cachedPaste, err := mc.Get(params["pasteid"])

That probably looks like shit on a blog. So just peek at the source.

Anyway, if you wanna give the pastebin a try, hit up http://paste.ronin.io/c7dcb578