modulepackage
0.0.0-20240604141907-80248a0899ff
Repository: https://github.com/ngthecoder/rss_scraper.git
Documentation: pkg.go.dev
# README
RSS Scraper API
This project sets up an HTTP server using the Chi router in Go, providing various endpoints for handling user and feed data. It connects to a PostgreSQL database and uses middleware for authentication. The API allows users to manage feeds, follow them, and fetch posts from the feeds. It also includes an RSS scraper that periodically scrapes feeds and updates the database.
Prerequisites
- Go programming language (version 1.16 or later)
- PostgreSQL
- Git (for cloning the repository)
- A .env file with the following variables
PORT=your_port_number
DB_URL=your_database_url
Files Overview
- main.go: Initializes the server, sets up routes, and configures the database connection.
- models.go: Defines the data models used in the application.
- rss.go: Contains the logic for processing and storing RSS feed data.
- scraper.go: Manages the periodic scraping of RSS feeds.
- json.go: Contains helper functions for JSON encoding and decoding.
- middleware_auth.go: Provides middleware for API key authentication.
- handler_readiness.go: Provides a health check endpoint.
- handler_err.go: Handles error simulation endpoints.
- handler_user.go: Manages user creation and retrieval endpoints.
- handler_feed.go: Handles feed creation and retrieval endpoints.
- handler_feed_follows.go: Manages endpoints for following and unfollowing feeds.
Getting Started
- Clone the repository:
git clone https://github.com/yourusername/rss-scraper.git
- Navigate to the project directory:
cd rss-scraper
- Install dependencies
go mod tidy
- Build the project:
go build
- Run the application:
./rss-scraper
The server will start running on the specified port (e.g., http://localhost:8080).
Endpoints
Authentication
When authentication is required, users must add an Authorization header with the value ApiKey {your_api_key_here}
.
Health Check
GET /v1/healthz
- Description: Checks the readiness of the server.
- Response: 200 OK
Error Simulation
GET /v1/err
- Description: Triggers an error for testing purposes.
- Response: 500 Internal Server Error
User Management
POST /v1/users
- Description: Creates a new user.
- Request Body: JSON object containing user data.
{
"name": "{name}"
}
- Response: 201 Created
GET /v1/users
- Description: Retrieves the current user.
- Authentication: Required.
- Response: 200 OK with user data.
Feed Management
POST /v1/feeds
- Description: Creates a new feed.
- Request Body: JSON object containing feed data.
{
"name": "{feed name}",
"url": "{feed URL}"
}
- Authentication: Required.
- Response: 201 Created
GET /v1/feeds
- Description: Retrieves all feeds.
- Response: 200 OK with a list of feeds.
Post Management
GET /v1/posts
- Description: Retrieves posts for the current user.
- Authentication: Required.
- Response: 200 OK with a list of posts.
Feed Follows Management
POST /v1/feed_follows
- Description: Follows a feed.
- Request Body: JSON object containing feed follow data.
{
"feed_id": "{feed id}"
}
- Authentication: Required.
- Response: 201 Created
GET /v1/feed_follows
- Description: Retrieves the feeds that the current user follows.
- Authentication: Required.
- Response: 200 OK with a list of followed feeds.
DELETE /v1/feed_follows/{feedFollowID}
- Description: Unfollows a feed.
- URL Parameter: feedFollowID - ID of the feed follow to delete.
- Authentication: Required.
- Response: 204 No Content
Contributing
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
# Packages
No description provided by the author