A summary of my experiences in rewriting the IronZebra blog from Django to Go. For the original HN front-page blog post, see http://www.ironzebra.com/code/103/i-rewrote-my-blog-in-go
3. A bit about Go
âž” Syntax somewhere between Python and
Java
package main
import "fmt"
func main() {
fmt.Println("Hello, 世界")
}
4. A bit about Go
âž” Compiled language
âž” Statically typed, but not stupid:
var hello string = “hi there” // valid
greeting := “how are you” // also valid
âž” Good compromise between ease of
development and efficiency
5. A bit about Go
âž” Very opinionated...
$ go fmt yourcode.go
$ go get github.com/hermanschaaf/ironzebra
...and that’s a good thing
6. âž” Learning & Fun
➔ The “Hello World” of web applications
âž” I did the same thing in Django
âž” The Django blog was reaaally sloooooow
âž” Fear of landing on HN front page (really!)
Reasons for rewriting my blog
7. What I want
âž” Markdown
âž” MongoDB
âž” Admin Login
âž” Faster load times
8. What I go get
âž” Markdown (github.com/russross/blackfriday)
âž” MongoDB (labix.org/v2/mgo)
âž” Admin Login (code.google.com/p/go.crypto/bcrypt)
âž” Faster load times (github.com/robfig/revel)
9. Markdown: blackfriday
$ go get github.com/russross/blackfriday
import "github.com/russross/blackfriday"
// markdown string
body := “Hello, _markdown_, my old *friend*.”
// parse markdown into HTML string
html := string(blackfriday.MarkdownCommon([]byte
(body)))
10. MongoDB: mgo
âž” mgo is a great wrapper for MongoDB
func getPosts(c Blog) ([]models.Post) (postList []
models.Post{}) {
collection := c.Database.C("posts")
query := bson.M{"published": true}
q := collection.Find(query).Sort("-timestamp")
q.Limit(10).Iter().All(&postList)
}
11. MongoDB: mgo
âž” ...but had some surprises:
collection.Find(
bson.M{"title": title}).One(&result)
17. BUT!!
âž” This was not a scientific experiment:
â—† Moved server to Heroku (git deploy!)
â—† Trimmed down the HTML, removed some queries
â—† Database used to be on same machine, now hosted
on Mongolab
18. Conclusions
âž” Site loading at least 10x faster
âž” Same amount of effort as Django, or less
➔ “Hello World” of web applications:
Proof of concept of what can be done when
not even trying very hard