go-skeleton
is a boilerplate for Golang projects. The project structure follows the Clean Code Architecture (Read here). This Skeleton made with Fiber Framework.
"Forget about the complexities of folder structures, and concentrate on growing your project!"
Features :
- REST API
- Clean Architecture
- Fiber Framework
- Api Docs with Swagger
- Worker Queue with RabbitMQ
- Implementation of Unit Test (with Testify and Mockery)
- Authentication with JWT RS512
- Logging with Zap Log
- GRPC Server! (IN PROGRESS)
- GRPC Server with handle authentication (Soon!)
- Caching with Redis (Soon!)
- Dependency Injection with Google Wire (Soon!)
- Worker Queue with Kafka (Soon!)
Feel free to contribute to this repository if you'd like!
Name | Role | |
---|---|---|
Rahmat Ramadhan Putra | rahmat.putra@spesolution.com | Creator |
- Git (See Git Installation)
- Go 1.19+ (See Golang Installation)
- Go Migrate CLI (See Migrate CLI Installation)
- MySQL (Download via Docker or Xampp or other sources)
- Mockery (See Mockery Installation)
- Redis (Optional based on your requirement) (See Redis Installation or use in Docker)
- RabbitMQ (Optional based on your requirement) (See RabbitMQ Installation or use in Docker)
- Install Make (See Make Installation).
- Clone this repo
git clone https://github.com/rahmatrdn/go-skeleton.git
- Copy
example.env
to.env
cp example.env .env
- Adjust the
.env
file according to the configuration in your local environment, such as the database or other settings - Create a MySQL database with the name
go_skeleton.
- Run database migration
make migrate_up
- Generate
private_key.pem
andpublic_key.pem
. You can generate them using an Online RSA Generator or other tools. Place the files in the project's root folder. - Start the API Service
go run cmd/api/main.go
- Start the Worker Service (if needed)
go run cmd/worker/main.go
For API docs, we are using Swagger with Swag Generator
- Install Swag
go install github.com/swaggo/swag/cmd/swag@latest
- Generate apidoc
make apidoc
- Start API documentations
go run cmd/api/main.go
- Access API Documentation with browser http://localhost:PORT/apidoc
tips: if you use VS Code
as your code editor, you can install extension golang.go
and follow tutorial showing code coverage after saving your code to help you create unit test
- Use Mockery to generate mock class(es)
make mock d=DependencyClassName
- Run unit test with command below or You can run test per function using Vscode!
make test
- Docker Build for API
docker build -t go-skeleton-api:1.0.1-dev -f ./deploy/docker/api/Dockerfile .
- Docker Build for Worker
docker build -t go-skeleton-worker:1.0.1-dev -f ./deploy/docker/worker/Dockerfile .
- Run docker compose for API and Workers
docker-compose -f docker-compose.yaml up -d
- Create a new branch with a descriptive name that reflects the changes and switch to the new branch. Use the prefix
feature/
for new features orfix/
for bug fixes.
git checkout -b <prefix>/branch-name
- Make your change(s) and make the test(s)
- Commit and push your change to upstream repository
git commit -m "[Type] a meaningful commit message"
git push origin branch-name
- Open Merge Request in Repository (Reviewer Check Contact Info)
- Merge Request will be merged only if review phase is passed.
Contact Creator!