Skip to content

aturanj/go-12factor-example

 
 

Repository files navigation

GO Example (Web Service)

Trying to implement follow The Twelve Factor App

Dependencies

  1. Command-line interface: github.com/spf13/cobra
  2. Configuration: github.com/spf13/viper
  3. Testing: github.com/stretchr/testify
  4. Mocking DB: github.com/DATA-DOG/go-sqlmock
  5. ORM: github.com/jinzhu/gorm
  6. Logging: github.com/op/go-logging
  7. HTTP Server: github.com/gin-gonic/gin

Project structure

.
├── Dockerfile
├── LICENSE
├── Makefile
├── README.md
├── cmd
│   ├── othercmd # example other command line app
│   └── server   # start reading code from here
├── internal
│   ├── api
│   ├── config
│   ├── models
│   ├── services
│   └── utils
├── config
│   └── default.yaml
├── dist
│   ├── drawin
│   ├── linux
│   └── windows
├── docker-compose.yml
├── go.mod
└── go.sum

Get started

Cross platform build environment setup

macOS

# install dep to build binary for linux and windows
brew install FiloSottile/musl-cross/musl-cross
brew install mingw-w64

Linux/Windows

# todo

Command Line

Run project with docker compose

docker compose -f dev.yml up --build

Run project without build

go run ./cmd/server [command] --[flag-name]=[flag-value]

Build using make command

# Build single binary with specify os
make build[-mac|win|linux]
# Build all os
make all
# Running test
make test
# Start server without build binary file
make run

Build with docker

docker compose build # build docker image
docker compose up # run on docker
# or
docker compose up --build # build and run
docker push [image-name] # public docker image to registry

Configuration

Viper uses the following precedence order. Each item takes precedence over the item below it:

  • explicit call to Set
  • flag
  • env
  • config
  • key/value store
  • default

About

Example the 12factor app using golang

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 83.4%
  • Makefile 6.7%
  • Shell 6.0%
  • Dockerfile 3.9%