- TODO Use configuration
-
Framework for API: Fiber
-
Package manager: go mod
-
Environment variables, config: Viper
-
Logger: zap
-
DI: Based on service container
-
Layers: Controller->Service->Repository->Entity
-
Process controller results and convert them into JSON/XML according to request headers
-
ORM: GORM
-
Migrations: gorm-goose
-
Base CRUD service
-
Base CRUD repository
-
Base CRUD controller
-
Request validation (Gin)
-
Console commands: Cobra
-
Unit tests with overriding of services in DI (
go test
) -
Code coverage by tests (
go tool cover
) -
Logger integration with Sentry: logrus_sentry
-
Setup alerting for unhandled errors
-
Swagger
-
Docker compose
doc/
: Project documentationdeploy/
: Artertacts related to deploymentapp/
: Artertacts related to application
docker-compose up --build
Check http://localhost:8080
sudo apt update
sudo apt upgrade
# See last version here: https://golang.org/dl/
wget https://dl.google.com/go/go1.12.5.linux-amd64.tar.gz
sudo tar -xvf go1.12.5.linux-amd64.tar.gz
sudo mv go /usr/local
sudo mcedit /etc/profile
And add last line:
export PATH=$PATH:/usr/local/go/bin
Update environment variables:
source /etc/profile
Check Go version:
go version
Now create folder for Go projects:
mkdir ~/go
cd ~/go
touch init.sh
mcedit init.sh
Paste next code into this file:
#!/bin/bash
export GOPATH=$HOME/go
export PATH=$PATH:$GOPATH/bin
Execute file:
chmod +x init.sh
source init.sh
git clone git@github.com:zubroide/go-api-boilerplate.git
cd go-api-boilerplate
./install/install.sh
cp .env.example .env
mcedit .env
go mod download
Create database go-api-boilerplate
.
And run migrations:
make migrate
make server
Or:
go run main.go server --port=8080
Check http://localhost:8080
Run all tests:
go test ./... -v -coverpkg=./... -coverprofile=coverage.out
go tool cover -html=coverage.out
Run test for one package:
go test go-api-boilerplate/test/unit -v -coverpkg=./... -coverprofile=coverage.out
Run one test:
go test test/unit/user_service_test.go -v -coverpkg=./... -coverprofile=coverage.out
Using make:
make test
Generate swagger.json:
make swagger
Documentation must be available at url http://localhost:8080/swagger/index.html
- Go 1.12+