I had a chance for the first time in a while to write some Go. I was writing a simple web API that allowed a user to login with JWT. This blog post is going to be about some of the challenges I faced along the way. I also want to give some shout outs to other blogs that helped me get it written.
If you haven’t had a chance to use Go before you are in luck. The documentation and the community are both great. One problem that I was trying to solve was finding a good protocol for encrypting and decrypting passwords. A quick google search showed some great results including this and this. Both led to a pretty seamless password storage process that I felt comfortable with.
Writing a web service in Go
One nice little perk from the project
One thing that I did that I found easier than most projects was write a full end to end test for the web server. The basic script was as follows.
go get go build -o /tmp/app /tmp/app & PID=$! go test echo "killing the app pid: $PID" kill $PID
Now here go shines beautifully. The test would simply fire up an http client make some requests on a health_check URL I built into the API. The output looked like this.
$ time ./build.sh test testing the app 2016/08/27 14:15:40 listening on 0.0.0.0:8080 PASS ok _/path/to/app 0.003s killing the app pid: 32440 ./build.sh test 1.26s user 0.15s system 124% cpu 1.136 total
It was pretty nice to have a full stack test that ran so quickly. Notice that the 1.26s comes from starting up the app. The tests ran rather quickly.
Overall I rather enjoyed Go. I’m definitely going to explore it more.