You can join in the development (Open Source). Let's Go!!!
Clean Architecture is an approach to organizing code in an application that focuses on separating responsibilities and dependencies between components. In the context of Golang, Clean Architecture refers to the application of Clean Architecture principles in developing applications using the Go programming language.
- Go Version
>= go 1.20
- PostgreSQL Version
>= version 15.0
There are 2 ways to do running
- Copy the example environment file and configure it:
cp.env.example .env
- Build Docker
docker-compose build --no-cache
- Run Docker Compose
docker compose up -d
- Clone the repository or Use This Template
git clone https://github.com/Caknoooo/go-gin-clean-starter.git
- Navigate to the project directory:
cd go-gin-clean-starter
- Copy the example environment file and configure it:
cp .env.example .env
- Configure
.env
with your PostgreSQL credentials:
DB_HOST=localhost
DB_USER=postgres
DB_PASS=
DB_NAME=
DB_PORT=5432
- Open the terminal and follow these steps:
- If you haven't downloaded PostgreSQL, download it first.
- Run:
psql -U postgres
- Create the database according to what you put in
.env
=> if using uuid-ossp or auto generate (check file /entity/user.go):CREATE DATABASE your_database; \c your_database CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; // remove default:uuid_generate_v4() if you not use you can uncomment code in user_entity.go \q
- Run the application:
go run main.go
To run migrations, seed the database, and execute a script while keeping the application running, use the following command:
go run main.go --migrate --seed --run --script:example_script
--migrate
will apply all pending migrations.--seed
will seed the database with initial data.--script:example_script
will run the specified script (replaceexample_script
with your script name).--run
will ensure the application continues running after executing the commands above.
To migrate the database schema
go run main.go --migrate
This command will apply all pending migrations to your PostgreSQL database specified in .env
To seed the database with initial data:
go run main.go --seed
This command will populate the database with initial data using the seeders defined in your application.
To run a specific script:
go run main.go --script:example_script
Replace example_script
with the actual script name in script.go at script folder
If you need the application to continue running after performing migrations, seeding, or executing a script, always append the --run
option.
By using this template, you get a ready-to-go architecture with pre-configured endpoints. The template provides a structured foundation for building your application using Golang with Clean Architecture principles.
You can explore the available endpoints and their usage in the Postman Documentation. This documentation provides a comprehensive overview of the API endpoints, including request and response examples, making it easier to understand how to interact with the API.
The repository includes templates for issues and pull requests to standardize contributions and improve the quality of discussions and code reviews.
- Issue Template: Helps in reporting bugs or suggesting features by providing a structured format to capture all necessary information.
- Pull Request Template: Guides contributors to provide a clear description of changes, related issues, and testing steps, ensuring smooth and efficient code reviews.