Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/by-sabbir/go-12factor-scaffold
An example of an event-driven microservice built with tweleve-factor methodology in Go
https://github.com/by-sabbir/go-12factor-scaffold
12-factor event-driven go microservice twelve-factor
Last synced: 3 months ago
JSON representation
An example of an event-driven microservice built with tweleve-factor methodology in Go
- Host: GitHub
- URL: https://github.com/by-sabbir/go-12factor-scaffold
- Owner: by-sabbir
- License: other
- Created: 2023-04-23T14:19:14.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-04-19T11:25:24.000Z (10 months ago)
- Last Synced: 2024-04-19T12:36:14.808Z (10 months ago)
- Topics: 12-factor, event-driven, go, microservice, twelve-factor
- Language: Go
- Homepage: https://sabbir.dev/article/twelve-factor-app-in-go/
- Size: 821 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go Rest micro-service
---
[![Go Report Card](https://goreportcard.com/badge/github.com/by-sabbir/go-12factor-scaffold)](https://goreportcard.com/report/github.com/by-sabbir/go-12factor-scaffold)Using 12Factor Methodology
## Instructions and Usage
| Action | Command |
|-----------|---------------|
|**Build** | `make build` |
|**Migrate**| `make migrate`|
|**Deploy** | `make run` |## Benchmard (write only)
```bash
PASS
ok github.com/by-sabbir/go-12factor-scaffold/transport/http 8.490s```
![by-sabbir/go-12factor-scaffold benchmark](./_example/benchtest.png)
### Help Text
```bash
Available Commands:
completion Generate the autocompletion script for the specified shell
help Help about any command
migrate Migrate Database
server runs the serverFlags:
--config string config file (default is ./config.yaml)
-h, --help help for 12Factor-App
-t, --toggle Help message for toggle
```### [The Twelve Factors](https://12factor.net/)
---
I. **Codebase**
Deployment is maintained from branches ie. `master -> production`, `dev -> test`, `staging -> uat`.II. **Dependencies**
In our case, `go.mod` files will seperate all the dependencies specifically for your project.III. **Config**
In this project we can pass configurations as parameter, `go run main.go server --config `.IV. **Backing services**
We used postgres and rabbitmq as the backing services and they can be attached from the config as we need.V. **Build, release, run**
Strictly separate build and run stages, means we have to maintain a CICD to seperate build, test, and deploy environments. For this example, I have seperated the stages with [Makefile](./Makefile)VI. **Processes**
This means we have to maintain our backend as a stateless independent process so that we can scale better. We are managing the application state in `rabbitmq` and it's fully independent.VII. **Port binding**
Export services via port binding, in our case `9091`VIII. **Concurrency**
Concurrency is built into go.IX. **Disposability**
I have used `SIGTERM` and `SIGKILL` for graceful shutdown. So that, the app waits for a specific amount of time to process existing concurrent request before it forcefully shuts down.X. **Dev/prod parity**
Again this depends on how we setup/plan our CICD. For our application we have `config.yaml` and `dev.yaml` for simulating this case.
Also for gin specific application, we can sperate debug/production with a environment variable - `GIN_MODE=release`XI. **Logs**
I have used `logrus` for structure logging.XII. **Admin processes**
[`cobra`](https://github.com/spf13/cobra) is used to create admin processes. Following admin processes are available in our app:```bash
migrate Migrate Database with golang-migrate
up Apply Migration
down Undo Migration (not implemented)
server runs the server
```