SongLibrary is a RESTful service for managing a music library. It enriches song data using an external API (you can test it by running this code) and stores it in a PostgreSQL database. Features include filtering, pagination, verse extraction, and Swagger documentation.
- Retrieve a list of songs with filtering by all fields and pagination
- Get song lyrics split into paginated verses
- Add new songs via JSON request (with enrichment from an external API)
- Update and delete existing songs
- Automatic database migration on startup
- Detailed logging with debug and info levels
- Swagger-generated API documentation
- Docker support for easy deployment
- Makefile for simplified development commands
- Go (Gin, GORM)
- PostgreSQL
- Docker / Docker Compose
- Swagger (Swaggo)
- Logrus (for logging)
Create a .env file in the project root and configure it like .env.example and external API URL here.
### 2. Build & Run via Makefile
```bash
# Build Docker images
make build
# Run containers (app + postgres)
make run
# Stop containers
make stop
# Clean containers, images, volumes
make clean
App will be available at:
http://localhost:8080
Swagger UI:http://localhost:8080/swagger/index.html
go mod tidygo run cmd/main.goswag init --generalInfo cmd/main.goRetrieve songs with filtering and pagination
Query Parameters:
id— Song IDgroup— Group namesong— Song namereleaseDate— Release date (2006-01-02,2006.01.02, or RFC3339)text— Text fragmentpage— Page number (default: 1)limit— Items per page (default: 10)
Retrieve song lyrics, split by paragraphs (double newline \n\n can change here)
Query:
page— Page number (default: 1)limit— Verses per page (default: 3)
Add a song using external API enrichment
Body:
{
"group": "Muse",
"song": "Supermassive Black Hole"
}Update a song by ID
Body:
{
"group_name": "Muse",
"song_name": "Starlight",
"release_date": "2006-07-16",
"text": "Ooh baby, don't you know I suffer...",
"link": "https://youtube.com/example"
}Delete a song by ID
The app uses gorm.AutoMigrate() to automatically create the required table.
Schema (simplified):
CREATE TABLE IF NOT EXISTS songs
(
id SERIAL PRIMARY KEY,
group_name TEXT NOT NULL,
song_name TEXT NOT NULL,
release_date DATE NOT NULL,
text TEXT NOT NULL,
link TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
CREATE UNIQUE INDEX IF NOT EXISTS unique_song ON songs (group_name, song_name);DEBUG— Incoming requests, parameters, external API callsINFO— Successful actions (song added/updated/deleted)ERROR— Failures in DB operations or external API responses
swag initAccessible at: http://localhost:8080/swagger/index.html
To remove all Docker containers, images, and volumes:
make clean