Creating a To-Do List App with Golang

Anjelica A
3 min readMar 3, 2021

I made a to-do list app in Flask and MongoDB a year ago, called busybee. My latest project was to re-create busybee in a different language — golang.

I already had a structure set for my to-do-list, but I found an easier, cleaner, and faster way of building the app thanks to a tutorial I found:

I used the gorilla/mux package for the router. I also used MongoDB for the database, just like the original busybee. With golang, you need to install a mongo driver package in order to connect the database.

Walkthrough

Create a Task

Type in a task in the textbox prompt and hit enter.

Task Completed

On completion of a task, click “done” icon of the respective task card.

You’ll notice on completion of task, the card’s bottom line color changed from yellow to green.

Undo a Task

To undo a task, click on the “undo” Icon,

You’ll notice on completion of task, card’s bottom line color changed from green to yellow.

Delete a Task

To delete a task, click the “delete” Icon.

The Router

Here is the router I built for the to-do list. The router handles the “GET/POST/PUT/DELETE” methods.

When adding a task, it calls the “POST” method, when retrieving all tasks, it uses the “GET” method, to mark a task as complete or undo a taks, it uses the “PUT” method, and to delete a task, it uses “DELETE.”

Middleware

Here are the functions I wrote up for the creation of tasks. It creates new tasks on the same page, so it does not need to refresh or redirect. Notice the router methods are being referenced here.

The code above is to add tasks to the MongoDB. The code is written so it first decodes the request body and stores it in the to do list model. Then, it will call the insertOneTask function and inserts the task into the collection.

Models

Here are the models I made. The assignment list and to do list were made to be identical on purpose, since it’s the same model structure. I made them separate, because I felt if we had tasks and assignments (home and work life) separate, it would easier to read. The ID is unique for every task, and the task/assignment is a string. The status is a bool, meaning if it is incomplete, it it marked as false, and if completed, marked true.

Conclusion

I like this version of busybee better because it is more efficient, simple and the code is easier to understand and follow. Unlike the original busybee, everything is done on the same page; no need for redirects and refreshes. Golang has a lot of good developer tools, and it is very easy to make a router with Go.

--

--