The project is under development, all versions until 1.0.0 are considered as not stable.

logo

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

Redis :6380 Database 0

PostgreSQL :5430 User/Password postgres Database balance_api


Down containers (volumes won't be destroyed)

make compose-down # docker-compose down

Debug build and run

  1. Generate swagger docs with swag
  2. Rebuild service image
make compose-debug 

Application endpoints

Default port: 8080


Docs

- Run application and open /swagger page

- Visit online API documentation


gRPC: 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

All options are loaded from .env

POSTGRES_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 ./...

Allure data: /tests/allure-results


Building and Running

1. Clone repository

`git clone https://github.com/illiafox/balance-api`

2. Setup env file

3. 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