/template-service-go

MadeiraMadeira boilerplate project to build scalable, testable and high performance Go microservices.

Primary LanguageGo

MadeiraMadeira Go Service Template

MadeiraMadeira boilerplate project to build scalable, testable and high performance Go microservices.

Table of Contents

Stack

Features

  • Automatic pre-commit code analysis and lint with golint, govet and goimports;
  • Automatic pre-push testing;
  • configuration: easily manage environment variables and app configuration;
    • it reads a .env file when its available, and load system variables when it's not;
    • it also validates the available variables based on the AppConfig struct;
  • healthcheck: REST endpoint that returns relevant information about the application status;
  • logger: easily manage application logs following the MMRFC1 standards;
  • Docker infrastructure with Docker Compose.

Getting started with boilerplate

Download and extract the project, then:

$ mv go-service-template-production {your_project_name}
$ git init
$ git remote add origin https://github.com/{user}/{repo}.git

Hint: use $ git remote -v to verify new remote

Hands On

Development

Docker setup

$ ./tools/setup.sh
$ docker-compose -f docker-compose.yml up

Local setup

$ ./tools/setup.sh
$ go mod download
$ go run ./cmd/SERVICE_NAME/main.go

# eg:
$ go run ./cmd/go_service_template/main.go

Test

# unit tests
$ go test ./...

# e2e tests
[soon]

# test coverage
[soon]

Improve tests output

To see a more friendly test output, install gotestsum globally by running

$ go install gotest.tools/gotestsum@latest

And execute at the project root directory:

$ gotestsum --format testname 

Release

$ docker build \
    --target release \
    --build-arg SERVICE_PATH=_SERVICE_NAME_ \
    -t _SERVICE_NAME_:VERSION \
    -f docker/Dockerfile .

# eg:
$ docker build \
    --target release \
    --build-arg SERVICE_PATH=go_service_template \
    -t go-service-template-production:latest \
    -f docker/Dockerfile .