Gator is a command-line application (CLI) built in Go that allows users to manage RSS feed subscriptions and aggregate posts from various feeds. It uses PostgreSQL as the backend database to store users, feeds, feed follows, and posts.
- User registration and login.
- Ability to follow and unfollow RSS feeds.
- Automatic fetching of RSS feeds and storing of posts in the database.
- Browse RSS posts in the terminal.
- Feeds are aggregated continuously in a long-running process.
- Middleware to handle logged-in users for specific commands.
Before running Gator, you'll need to have the following installed on your system:
- Go: You can install it via this link.
- PostgreSQL: Install using your system's package manager (e.g. Homebrew for macOS or apt for Linux).
On macOS, you can install PostgreSQL using Homebrew:
brew install postgresql
brew services start postgresql
To install the Gator CLI, use the go install
command:
go install github.com/Romasav/gator@latest
Gator requires a PostgreSQL database to function. You can set it up by creating a database:
createdb gator
After creating the database, you can apply the migrations using Goose:
goose postgres "postgres://username:password@localhost:5432/gator?sslmode=disable" up
Make sure to update the database connection string to match your PostgreSQL setup.
The config file, .gatorconfig.json
, needs to be located in your project’s root directory. This file holds important configuration, including the currently logged-in user and database connection URL.
{
"current_user_name": "your-username",
"db_url": "postgres://your-username:your-password@localhost:5432/gator?sslmode=disable"
}
To initialize the configuration, create the .gatorconfig.json
file in your project root directory with your PostgreSQL details.
You can run Gator by using the following command:
./gator <command> [arguments...]
-
Login: Login as an existing user.
./gator login <username>
-
Register: Create a new user.
./gator register <username>
-
Reset: Delete all users from the database.
./gator reset
-
Add Feed: Add a new feed to follow.
./gator addfeed <feed-name> <feed-url>
-
Browse: Browse posts from the feeds you follow.
./gator browse [limit]
-
Aggregator: Continuously fetch new posts from all followed feeds.
./gator agg <time_between_reqs>
-
Follow a Feed: Follow an existing feed.
./gator follow <feed-url>
-
Unfollow a Feed: Unfollow a feed.
./gator unfollow <feed-url>
-
Show Followed Feeds: Display all feeds the user is following.
./gator following
Migrations are managed using Goose. Migrations can be found in the sql/schema
directory.
To apply migrations, run:
goose postgres "postgres://username:password@localhost:5432/gator?sslmode=disable" up
SQLC is used to generate type-safe Go code from SQL queries. Queries are stored in the sql/queries
directory. To regenerate Go code from SQL queries, run:
sqlc generate
For development, you will need to install Goose and SQLC for managing database migrations and generating Go code from SQL queries:
go install github.com/pressly/goose/v3/cmd/goose@latest
go install github.com/kyleconroy/sqlc/cmd/sqlc@latest