1.0.0
are considered as not stable.
The project is under development, all versions until
REST API for ready User balance integration
- One-tap deployment with docker-compose
- Exchange rates via redis
- Caching (will be extended in future releases)
- Swagger API documentation + Client generation
- Pprof, Prometheus metrics
- PostgreSQL
- Tests (very soon)
- gRPC
- Rewritten in Rust
API features:
- Get/Change balance
- Transfer between users
- View transaction history
- Block/Unblock balance
- Taxes
- Actions with blocked user
Deployment
docker-compose
Service starts immediately after containers are up
make compose # docker-compose up
:6380
Database 0
Redis :5430
User/Password postgres
Database balance_api
PostgreSQL Down containers (volumes won't be destroyed)
make compose-down # docker-compose down
Debug build and run
- Generate swagger docs with
swag
- Rebuild service image
make compose-debug
Application endpoints
8080
Default port: -
/api/
- REST API -
/swagger
- Swagger API documentation -
/metrics
- Prometheus metrics -
/debug/pprof/
- pprof
Docs
/swagger
page
- Run application and open API documentation
- Visit onlinegRPC: soon or never
Logs
# Terminal (stdout)
15/07 09:58:22 | INFO | app/handler.go:19 | Initializing storages
15/07 09:58:22 | INFO | app/handler.go:37 | Initializing handlers
15/07 09:58:22 | INFO | app/handler.go:63 | Swagger enabled {"endpoint": "/swagger"}
15/07 09:58:22 | INFO | app/handler.go:75 | Pprof enabled {"endpoint": "/debug/pprof"}
15/07 09:58:22 | INFO | app/handler.go:82 | Prometheus metrics enabled {"endpoint": "/metrics"}
15/07 09:58:22 | INFO | app/listen.go:45 | Server started {"address": "0.0.0.0:8080", "https": false}```
# File (default log.txt)
{"level":"info","ts":"Fri, 15 Jul 2022 09:58:22 UTC","caller":"app/handler.go:19","msg":"Initializing storages"}
{"level":"info","ts":"Fri, 15 Jul 2022 09:58:22 UTC","caller":"app/handler.go:37","msg":"Initializing handlers"}
{"level":"info","ts":"Fri, 15 Jul 2022 09:58:22 UTC","caller":"app/handler.go:63","msg":"Swagger enabled","endpoint":"/swagger"}
{"level":"info","ts":"Fri, 15 Jul 2022 09:58:22 UTC","caller":"app/handler.go:75","msg":"Pprof enabled","endpoint":"/debug/pprof"}
{"level":"info","ts":"Fri, 15 Jul 2022 09:58:22 UTC","caller":"app/handler.go:82","msg":"Prometheus metrics enabled","endpoint":"/metrics"}
{"level":"info","ts":"Fri, 15 Jul 2022 09:58:22 UTC","caller":"app/listen.go:45","msg":"Server started","address":"0.0.0.0:8080","https":false}```
Flags
docker-compose
app:
command:
- "-pprof" # pprof
- "-swagger" # swagger docs
- "-prom" # prometheus docs
- "-https"
Standalone run
With non-standard log file path:
app -log=log.txt
HTTPS
app -https
Docs and Metrics
app -swagger -prom -pprof
Config
.env
All options are loaded fromPOSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
...
REDIS_HASHMAP=currency
...
HOST_ADDRESS=0.0.0.0
HOST_PORT=8080
docker-compose overrides database credentials
Tests
SOME TEST WON'T PASS WITHOUT WORKING APPLICATION
go test ./...
/tests/allure-results
Allure data: Building and Running
1. Clone repository
`git clone https://github.com/illiafox/balance-api`
env file
2. Setup3. Build and Run
make build
make run # ./app
PostgreSQL Migrations
migrate -database ${POSTGRESQL_URL} -path migrate/ up
Redis
Example: Store currencies in Hash
HSET currency EUR 65
Where currency
is Redis Hash
Name