Skip to content
/ microservices-go Public template

Golang Microservice Boilerplate using MySQL, Docker and Swagger, API REST. Gin Go and GORM with pagination and implementation of a Clean Architecture.

License

Notifications You must be signed in to change notification settings

gbrayhan/microservices-go

Repository files navigation

Golang Microservices Boilerplate - Clean Architecture

issues forks stars license CodeFactor Codacy Badge

Example structure to start a microservices project with golang. Using a MySQL databaseSQL. Using a Hexagonal Architecture tha is a Clean Architecture.

Manual Installation

If you would still prefer to do the installation manually, follow these steps:

Clone the repo:

git clone https://github.com/gbrayhan/microservices-go

If you need, configure the environment variables in file config.json, if you use docker-compose leave the variables set in the file config.json.example

cp config.json.example config.json

TL;DR command list

git clone https://github.com/gbrayhan/microservices-go
cd microservices-go
cp config.json.example config.json
docker-compose up  --build  -d

Table of Contents

Features

  • Golang v1.21: Stable version of go
  • Framework: A stable version of gin-go
  • Token Security: with JWT
  • SQL databaseSQL: MariaDB using internal sql package of go sql
  • Testing: unit and integration tests using package of go testing
  • API documentation: with swaggo @latest version that is a go implementation of swagger
  • Dependency management: with go modules
  • Environment variables: using viper
  • Docker support
  • Code quality: with CodeFactor and Codacy
  • Linting: with golangci-lint an implementation of a Golang linter

Commands

Build and run image of docker

docker-compose up  --build  -d

Swagger Implementation

swag init -g src/infrastructure/rest/routes/routes.go

To visualize the swagger documentation on local use

http://localhost:8080/v1/swagger/index.html

To see the postman collection use

https://www.postman.com/kts-mexico/workspace/boilerplategomicroservice

Unit test command

# run recursive test
go test  ./test/unit/...
# clean go test results in cache
go clean -testcache

Lint inspection of go

golangci-lint run ./...