Member-only story
Web Service Architecture for Golang Developers

Web service architecture is the first phase before building every project, it’s like you prepare to build a house and start by creating the architecture plan.
This article will present how I structure my projects when I need to create a simple web service in Golang. It’s very important for you to keep a simple but intuitive architecture, because as you know, in golang you can call methods by referencing the package name.
In the following lines I’ll present a simple, but traditional model of web service architecture used by me in most of the projects that I’m involved in, treating each individual web service’s component.
/api
The API package is the folder where all the API endpoints are grouped into sub-packages by the purpose they serve. That means, I prefer to have a special package with it’s main scope to solve a specific problem.
For example all the login, register, forgot password, reset password handlers, I prefer to be defined into a package named registration.
The registration package can look like below:
.
├── api
│ ├── auth
│ │ ├── principal.middleware.go
│ │ └── jwt.helper.go
│ ├── cmd
│ │ └── main.go
│ ├── registration
│ │ ├── login.handler.go
│ │ ├──…