An RSS Aggregator application built using Go, designed to fetch, parse, and serve RSS feeds with support for database operations, authentication, and scalable service components.
- api
docs.go
swagger.json
swagger.yaml
- cmd
- rss-aggregator
main.go
- config
config.go
- internal
- auth
auth.go # Handles API key extraction and validation from requests
- database
# Auto-generated files by sqlc for database interactions
- handler
*_handler.go # Handles requests and performs database operations
- middleware
auth.go # Middleware for authentication
config.go # Middleware for application configuration
- models
# Model classes to structure responses returned to the client
- platform
- database
connection.go
migrations.go
- service
rss_service.go # Core business logic for RSS feed management
scraper_service.go # Logic for scraping RSS feeds from external sources
- utils
json_response.go # Utility for standardized JSON responses
- sql
- queries
# SQL query files for interacting with database tables
- schema
# SQL schema files for creating tables and other database structures
- vendor
.env # Environment variables
.env.example # Example environment file
.env.local # Local environment variables
.gitignore # Git ignore file
docker-coimpose.yaml # Docker compose file
Dockerfile # Dockerfile
go.mod # Go module definition
go.sum # Dependency checksums
LICENSE # Project license
README.md # Project documentation
sql.yaml # SQLC configuration file
- Go (v1.18 or higher)
- PostgreSQL or any compatible database
sqlc
for generating database interaction codeswag
for generating Swagger documentation- Docker and Docker Compose
-
Clone the repository:
git clone <repository-url> cd rss-aggregator
-
Install dependencies:
go mod tidy
-
Install
swag
:go install github.com/swaggo/swag/cmd/swag@latest
-
Configure the environment variables:
- Create a
.env
file based on the.env.example
file and fill in the necessary values.
- Create a
-
Generate database interaction files with
sqlc
:sqlc generate
You can use Docker Compose to simplify the process of running the application along with its dependencies.
-
Build and start the application:
docker-compose up --build
-
The application should now be running on the configured port (default:
8080
). -
Access the application:
http://localhost:8080
-
Stop the application:
docker-compose down
-
Start the server:
go run cmd/rss-aggregator/main.go
-
The application should now be running on the configured port (default:
8080
).
This project includes a Swagger UI for exploring and testing the API endpoints.
-
Run the application as described in the Running the Application section.
-
Open your browser and navigate to:
http://localhost:1907/swagger/index.html
Swagger annotations are included in the codebase to document API endpoints. For example:
// HandlerGetPosts retrieves posts for a user.
// @Summary Get posts for a user
// @Description Retrieve all posts for a specific user
// @Tags Posts
// @Accept json
// @Produce json
// @Security ApiKeyAuth
// @Success 200 {array} models.Post
// @Failure 400 {object} utils.JSONErrorResponse
// @Router /posts [get]
- Interactive Testing: Test API endpoints directly from the browser.
- Comprehensive Documentation: View detailed information about each endpoint, including required parameters, response types, and error codes.
- Authorization Support: Use the "Authorize" button to add API keys for testing secured endpoints.
To generate or update Swagger documentation, use the following command:
swag init -g main.go -d cmd/rss-aggregator,internal/handler,internal/utils/json_response.go,internal/models/models.go --output ./api --parseDependency --parseInternal
This will generate the Swagger files (docs.go
, swagger.json
, swagger.yaml
) in the api
directory.
- Authentication: Secure API key-based authentication for requests.
- RSS Management: Fetch, parse, and serve RSS feeds.
- Database Integration: Store and manage RSS data in a relational database using
sqlc
. - Scalable Design: Organized project structure to support modular development.
Auto generated swagger files
Contains the entry point of the application (main.go
). This is where the application starts.
Defines application configuration settings, such as environment variable parsing and application constants.
Handles API key extraction and validation from incoming requests.
Contains sqlc
-generated files for database interaction.
Defines HTTP handlers for managing requests and performing operations on the database.
Defines middleware for authentication and configuration loading.
Contains model classes for structuring responses returned to the client.
connection.go
: Initialization connection to the database and run migrations.migrations.go
: Contains code for running migrations on db.
routes.go
: Contains all routes.
rss_service.go
: Contains core business logic for RSS feed management.scraper_service.go
: Implements scraping logic to fetch RSS feeds from external sources.
Contains utility functions, such as standardized JSON response formatting.
Contains SQL query files for database interactions.
Contains SQL schema files for creating tables and other database structures.
.env
,.env.example
,.env.local
: Environment variable files..gitignore
: Specifies intentionally untracked files to ignore.go.mod
,go.sum
: Go module and dependency files.LICENSE
: Specifies the project license.README.md
: Project documentation.sql.yaml
: Configuration forsqlc
.
This project is licensed under the terms of the MIT License.
Feel free to contribute to the project by opening issues or submitting pull requests. Make sure to follow the contribution guidelines.
For any inquiries, please contact me at gulmammadovtabriz@gmail.com.