A REST API built with Go and Gin framework for managing financial transactions with full CRUD operations and MySQL database integration.
- Full CRUD Operations: Create, Read, Update, and Delete transactions
- Filter by Type: Get transactions by income/expense type
- Input Validation: Data validation with proper error handling
- Modular Architecture: Clean separation with controllers, models, routes
- JSON API: RESTful endpoints with JSON responses
- Language: Go 1.24.1
- Framework: Gin v1.10.0
- Database: MySQL
- Driver: go-sql-driver/mysql v1.9.2
transaction-tracker/
├── controllers/ # HTTP handlers
├── database/ # DB connection
├── models/ # Data structures
├── routes/ # Route definitions
├── create-tables.sql # Database schema
├── main.go # Entry point
└── README.md
- Clone and install:
git clone https://github.com/MalshaPG/transaction-tracker.git
cd transaction-tracker
go mod tidy- Set environment variables:
# Linux/Mac
export DBUSER=username
export DBPASS=password
# Windows
set DBUSER=username
set DBPASS=password-
Setup database: Run the SQL from
create-tables.sqlto create the database and sample data. -
Run the application:
go run main.goServer starts on localhost:8080
| Method | Endpoint | Description |
|---|---|---|
| GET | /transactions |
Get all transactions |
| GET | /transactions/:type |
Get transactions by type |
| POST | /transactions |
Create a new transaction |
| PUT | /transactions/:id |
Update a transaction |
| DELETE | /transactions/:id |
Delete a transaction |
Get all transactions:
curl http://localhost:8080/transactionsCreate transaction:
curl -X POST http://localhost:8080/transactions \
-H "Content-Type: application/json" \
-d '{
"type": "income",
"description": "Salary",
"date": "2025-01-20",
"amount": 5000.00
}'Update transaction:
curl -X PUT http://localhost:8080/transactions/1 \
-H "Content-Type: application/json" \
-d '{
"type": "expense",
"description": "Updated expense",
"date": "2025-01-20",
"amount": 100.00
}'Delete transaction:
curl -X DELETE http://localhost:8080/transactions/1{
"id": 1,
"type": "income", // "income" or "expense"
"description": "Salary", // required, max 200 chars
"date": "2025-01-01", // YYYY-MM-DD format
"amount": 5000.00 // must be > 0
}- Type: Must be "income" or "expense" (case-insensitive)
- Description: Required, non-empty, max 200 characters
- Date: Required, YYYY-MM-DD format
- Amount: Required, must be greater than 0
CREATE TABLE transactions (
id INT AUTO_INCREMENT NOT NULL,
type VARCHAR(100) NOT NULL,
description VARCHAR(200) NOT NULL,
date DATE NOT NULL,
amount DECIMAL(20, 2) NOT NULL,
CONSTRAINT pk_transactions PRIMARY KEY (id)
);200 OK- Successful GET/PUT201 Created- Successful POST204 No Content- Successful DELETE400 Bad Request- Invalid input404 Not Found- Resource not found500 Internal Server Error- Server/DB error
This is a personal project made available for educational purposes. Feel free to fork and use as you like.