A weekend with Go lang, BeeGo & React


So I’ve decided this weekend to take Go language for a ride.

I have started with Go’s awesome tour to understand what it is all about. To be honest it is quite different from my daily Ruby, yet cool enough to get me in.

Why Go and not Node.js?

the $1 million question, right?
I have never written anything big in Node, nor in Go so I am not familiar with real-life problems. I have done some mini projects to figure out what Node is all about and I love Node’s ecosystem. My friends from mean.io have done some amazing stuff with Node.
My 2 cents answer to the question: “I am afraid of Node’s callback nightmare” + I want to learn something new + some cool projects @work are in Go (openshift) to name one.

So, once I’ve comlpeted the tutorial, I have decided on my weekend project: A blog!
I mean, we never have enough of how to create blogging system 🙂

Next, I started looking for a go web framework. This is a bad practice because you can build everything in Go. from my minimal understanding those frameworks are mainly wrappers to existing libraries in Go.
There are quite a few Go frameworks: Beego, Martini, Gorilla, Revel & GoCraft to name a few. However, more experienced Go developers will tend towards Go’s Net/HTTP.
After some reading (and because I like honey), I chose Beego which seemed the easier choice for a newbie.


Installing in Go is quite simple, you just run:

go get github.com/astaxie/beego
go get github.com/astaxie/bee (cli)

And now you’ve go two options to start a new project:
> bee new myproject – to create a new MVC ( where the view is HTML)
> bee api myproject  – to create a new MVC API (so the view is JSON)

I chose the API project, as I wanted to use React as my frontend.
I have deleted all the demo controllers & models and started from scratch.

The Model:
It took me sometime to get to this model, and I am sure I can make it better (contributions welcome). And so I have crafted struggled my way to create a CRUD API which displays, creates, updates and deletes Posts. The Controller:

Finally, I had an API responding to “/v1/posts”.

Next was React.
I have followed their fine tutorial and moved it from comments (the tutorial) to Posts.
The React app looks like:

The final outcome is at: https://github.com/shlomizadok/beego_react
(fork, learn, make better 🙂 )

Eventually, I have pushed it to Heroku so others can try.
Try it (and write something nice…)