Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/utain/go-12factor-example
Example the 12factor app using golang
https://github.com/utain/go-12factor-example
12-factor cobra docker example gin gin-gonic golang gorm webservice
Last synced: 4 months ago
JSON representation
Example the 12factor app using golang
- Host: GitHub
- URL: https://github.com/utain/go-12factor-example
- Owner: utain
- License: mit
- Created: 2019-12-10T12:05:26.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2023-05-05T02:32:03.000Z (over 1 year ago)
- Last Synced: 2024-10-02T05:22:38.986Z (4 months ago)
- Topics: 12-factor, cobra, docker, example, gin, gin-gonic, golang, gorm, webservice
- Language: Go
- Homepage:
- Size: 297 KB
- Stars: 51
- Watchers: 2
- Forks: 12
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GO Example (Web Service)
Trying to implement follow [The Twelve Factor App](https://12factor.net/)
## 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: gorm.io/gorm
6. Logging: github.com/op/go-logging
7. HTTP Server: github.com/gin-gonic/gin
8. API Document: github.com/swaggo/swag/cmd/swag## Project structure
```sh
.
├── Dockerfile
├── LICENSE
├── Makefile
├── README.md
├── cmd
│ ├── othercmd # example other command line app
│ └── server # start reading code from here
├── internal
│ ├── api/v1
│ ├── config
| |-- dto
│ ├── entities
| |-- errors
| |-- log
│ ├── services
│ └── utils
├── config
│ └── default.yaml
├── docs
├── dist
│ ├── drawin
│ ├── linux
│ └── windows
├── docker-compose.yml
├── go.mod
└── go.sum
```## Get started
### Cross platform build environment setup
**macOS**
```sh
# install dep to build binary for linux and windows
brew install FiloSottile/musl-cross/musl-cross
brew install mingw-w64
```**Command Line**
Run project with docker compose
```sh
docker compose -f dev.yml up --build
```Run project without build
```sh
go run ./cmd/server [command] --[flag-name]=[flag-value]
```Generate API Document
```sh
make doc
# open url http://localhost:5000/doc/index.html
```Build using `make` command
```sh
# 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
```sh
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](https://github.com/spf13/viper#why-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## Example List
- Simple in [main branch](https://github.com/utain/go-12factor-example)
- Port/Adapter in [hexagonal branch](https://github.com/utain/go-12factor-example/tree/hexagonal)