Starting my first Go Application

James Howard
3 min readMar 3, 2024

--

It’s been a while since I’ve started developing something new so this weekend, I decided to make a start on an entirely new application that I’ve been kicking around for a while. I’d been toying with the idea of starting the backend in Laravel but since we’ve been using Go in work, I decided in the end to give it a try since I’d been very impressed with its simplicity and high performance. I’d gone through a Udemy course on Go, so between that and experience with the dozen or so other languages I’ve worked in, I reckoned I was good enough to get started.

Tools

Since I already have a univeral JetBrains subscription and am very familiar with the tools, GoLand seemed the obvious choice for a development IDE. After a quick download, I was up and running in no time. As the app is going to need a database, I decided to stick with MySQL since that’s what I normally use. I’ll try to stick with an ORM as long as possible so a DB engine swap should not really cause a lot of bother when I go to deployment. I’ve decided to skip dockerisation for the moment as I just want to get a few bits of code together first.

I’ve also created a private repository on bitbucket and also set up a JIRA software board in Kanban mode to keep track of what I’m doing. This will help a lot later but it’s a little pointless now.

Registration & Authentication

So, what next? I figured the best place to start was on registration and authentication since I was going to need it and it’s easier to add it before doing anything else of note. Implementing this and the associated unit testing would make a reasonable goal for the weekend.

I did a bit of searching and came up with this awesome tutorial on implementing login and registration using the exact stack I was planning on. This took a couple of hours to go through and understand but I hit no real snags. Once I was done with that, it was time to figure out unit testing.

Unit Tests

I’d already gotten along a little further than I was comfortable doing without Unit Tests but Go really has your back on unit testing so this turned out to be relatively easy.

The first step was to test the simple little Token util class. This turned out to be relatively simple as it was really just a matter of generating a token and then running a few asserts on it. I hit a minor snag with reading the environment variables but that was a simple matter of setting the appropriate values in the test setup

The next step was to test the user model. This turned out to be a little more complex as I was going to have to mock the DB for this. After a little research, it appears that the DATADOG sql mock driver does exactly what I need it. You can define a response expected from a query and when GORM exectutes something that matches the RegEx, the appropriate response will be injected into the model. Quite an elegant solution.

The final step was to figure out the controllers testing pattern. This involved creating a mock context and faking the http parameters passed to the context so that the response can be checked. I also needed to mock up the DB here but so far there’s not a lot of difficuly here while things remain simple.

Next Steps

So far so good - I’ve got the authentication and registration flow implemented and most of it unit tested. I’ll need to come back and write a few more tests on the registration as these require different database mocking patterns. But the next step is to get started on implementing a front-end for what I’ve done so far. This will almost certainly be React as that’s something else I’ve been doing courses on but not actually worked with.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

James Howard
James Howard

No responses yet

Write a response