This is a REST API built with Golang and the Fiber framework. This repository also includes a payment gateway if your service requires one.
Clean Architecture is a software design philosophy that emphasizes the separation of concerns, making the codebase more maintainable, testable, and scalable. In this example, the Go Fiber application follows Clean Architecture principles by organizing the code into distinct layers, each with its own responsibility.
- Entities (Core Business Logic)
- Located in the pkg/entities directory.
- Contains the core business logic and domain models, which are independent of any external frameworks or technologies.
- Use Cases (Application Logic)
- Located in the pkg/ directory (example: pkg/user).
- Contains the application-specific business rules and use cases. This layer orchestrates the flow of data to and from the entities.
- Interface Adapters (Adapters and Presenters)
- Located in the api directory.
- Contains the HTTP handlers, routes, and presenters. This layer is responsible for converting data from the use cases into a format suitable for the web framework (Fiber in this case).
- Frameworks and Drivers (External Interfaces)
- Located in the cmd directory.
- Contains the main application entry point and any external dependencies like the web server setup.
add on: In this project I use Qodana, Static code analysis by Qodana helps development teams to follow agreed quality standards and deliver readable, maintainable and secure code by JetBrains. If you want to test it on your code, just install Qodana and run it with:
qodana scan
- Clone this repository:
git clone https://github.com/paundraP/Go-Starter-Template.git cd Go-Starter-Template
- Set the environment variables in a
.env
file:cp .env.example .env
- Install the dependencies:
go mod download
- Run the application:
-
At the first, migrate and seed the database:
go run cmd/database/main.go -migrate -seed
-
Then you can run with air to automatically reload your application during development whenever you make changes to the source code (dont forget to install air first)
go install github.com/air-verse/air@latest
- If you use mac:
air -c .air.toml
- If you use windows:
air -c .air.windows.conf
- If you use linux:
air -c .air.windows.conf
- If you use mac:
The API should now be running on http://127.0.0.1:3000.