Golang API with gorilla mux and gorm

I recently self-learned and created a Golang API project structure, inspired by what I used to do with .NET projects. Before this, I also experimented with project structures in Node.js and MongoDB.

As a Senior Software Engineer, I wanted to expand my skills beyond .NET and not be tied to just one language. Although I haven’t had much real-world experience with Node.js and Golang APIs, I aimed to follow best practices in creating a good Golang API project structure.

The application is simple, with features for login, registration, and CRUD operations for books and categories. Authorization is managed with Basic Auth for registration and login, and a Bearer Token for actions after login. Additionally, I’ve implemented single-device login. The database for this Golang API is MySQL.

The Project structure as below:

go-bookstore/
├─ node_modules/
├─ api/
│ ├─ common/
│ ├─ controllers/
│ ├─ docs/
│ ├─ helper/
│ ├─ middlewares/
│ ├─ models/
│ ├─ repository/
│ ├─ routes/
│ ├─ utils/
│ main.go

In addition, I’ve included a Postman collection in the project folder for your convenience. You can use it to try out the API and explore its functionality.

For those interested in exploring the project further, here is the GitHub repository link where you can check it out:
https://github.com/kyawzaymoore/go-bookstore

1 Comment

Leave a Comment

Your email address will not be published. Required fields are marked *