A REST API service for managing user wallets and balances, built with Go. The service supports concurrent operations (up to 1000 RPS per wallet) and provides endpoints for creating wallets, checking balances, and performing deposit/withdrawal operations.
- Wallet Management: Create, retrieve, and delete user wallets
- Balance Operations: Deposit and withdraw funds with concurrent safety
- REST API: OpenAPI 3.0 compliant endpoints
- Database: PostgreSQL with GORM ORM
- Logging: Structured logging with Zap
- Docker Support: Containerized deployment with multiple profiles (debug, test, release)
- Testing: Unit and integration tests included
- Language: Go 1.24.5
- Framework: Echo v4
- Database: PostgreSQL
- ORM: GORM
- Configuration: Viper
- API Documentation: OpenAPI 3.0
- Logging: Zap
- Testing: Testify
.
├── api/
│ ├── handlers/ # HTTP request handlers
│ ├── middleware/ # Custom middleware
│ └── openapi/ # Generated OpenAPI client/server code
├── build/ # Dockerfiles for different environments
├── cmd/app/ # Application entry point
├── configs/ # Docker Compose configurations
├── internal/
│ ├── app/ # Business logic (services, repositories)
│ ├── config/ # Configuration management
│ └── models/ # Data models
├── test/ # Test files
├── .env # Environment variables
├── go.mod # Go module definition
└── README.md
- Go 1.24.5 or later
- Docker and Docker Compose
- PostgreSQL (if running locally without Docker)
-
Clone the repository
git clone https://github.com/ichigo7diabol/go-test-wallet.git cd go-test-wallet -
Start the application in release mode
docker-compose --profile release up --build
The API will be available at
http://localhost:8080/api/v1
-
Clone and setup
git clone https://github.com/ichigo7diabol/go-test-wallet.git cd go-test-wallet -
Install dependencies
go mod tidy
-
Setup PostgreSQL
- Install PostgreSQL locally, or
- Use Docker:
docker run -d --name postgres -p 5432:5432 -e POSTGRES_PASSWORD=12345678 postgres:16
-
Configure environment
- Copy
.envand adjust database connection if needed
- Copy
-
Run the application
go run cmd/app/main.go
Run with debugging enabled:
docker-compose --profile debug up --buildConnect debugger to port 40000.
Run all tests:
docker-compose --profile test up --buildOr locally:
go test ./...Build for production:
docker-compose --profile release up --buildThe API is documented using OpenAPI 3.0. The specification is available in api/openapi.yaml.
http://localhost:8080/api/v1
GET /wallets- List all walletsPOST /wallets- Create a new walletGET /wallet/{walletId}- Get wallet informationDELETE /wallet/{walletId}- Delete a wallet
POST /wallet- Perform balance operation (DEPOSIT/WITHDRAW)
Create Wallet:
curl -X POST http://localhost:8080/api/v1/wallets \
-H "Content-Type: application/json" \
-d '{"initialBalance": 1000.00}'Deposit Funds:
curl -X POST http://localhost:8080/api/v1/wallet \
-H "Content-Type: application/json" \
-d '{
"walletId": "b1f04c42-2b54-4b73-996c-cc0d0579b5c0",
"operationType": "DEPOSIT",
"amount": 500.00
}'Check Balance:
curl http://localhost:8080/api/v1/wallet/b1f04c42-2b54-4b73-996c-cc0d0579b5c0The application uses environment variables for configuration:
| Variable | Description | Default |
|---|---|---|
WALLET_APP_PORT |
Server port | 8080 |
WALLET_APP_DSN |
Database connection string | - |
WALLET_APP_DEBUG_PORT |
Debug port | 40000 |
Database environment variables (for Docker):
POSTGRES_USERPOSTGRES_PASSWORDPOSTGRES_DBPOSTGRES_PORT
This project is licensed under the MIT License.