A blog aggregator in Golang. Guided by Boot.dev.
- A working installation of PostgreSQL v15 or later. Refer to the documentation.
- A working installation of Golang. See https://go.dev/doc/install.
Clone the repository and head into the root directory of the project.
git clone https://github.com/uncomfyhalomacro/gator
cd gatorStart the Postgres server in the background
- Mac: brew services start postgresql@15
- Linux: sudo service postgresql start
Connect to the server. I recommend simply using the psql client. It's the "default" client for Postgres, and it's a great way to interact with the database. While it's not as user-friendly as a GUI like PGAdmin, it's a great tool to be able to do at least basic operations with.
Enter the psql shell:
- Mac: psql postgres
- Linux: sudo -u postgres psql
You should see a new prompt that looks like this:
postgres=#
Create a new database.
CREATE DATABASE gator;
Connect to the new database:
\c gator
You should see a new prompt that looks like this:
gator=#
Set the user password (Linux only)
ALTER USER postgres PASSWORD 'postgres';
You can type exit to leave the psql shell.
Get your connection string. A connection string is just a URL with all of the information needed to connect to a database. The format is:
protocol://username:password@host:port/database
Install goose
go install github.com/pressly/goose/v3/cmd/goose@latestWhile inside your local copy of the repository, head to sql/schema/ directory
and run the command
goose postgres "postgres://postgres:@localhost:5432/gator" upThis should set up all the tables for the gator database.
Create a config file called .gatorconfig.json at your $HOME directory.
The JSON file should have this structure (when prettified):
{
"db_url": "postgres://postgres:@localhost:5432/gator?sslmode=disable"
}The db_url is your connection string, appended with ?sslmode=disable.
You need sqlc to generate Go code. See https://docs.sqlc.dev/en/latest/overview/install.html.
Then run sqlc generate to generate Go code.
go build
./gator register yourUsername # You are automagically logged in
./gator addfeed "Hacker News RSS" "https://hnrss.org/newest"./gator aggIn another terminal, you can check and browse your followed feeds.
./gator browse
./gator browse 10Checkout the other subcommands below.
followingchecks the list of followed RSS feeds for the currently logged in userloginlogins a registered userresetresets the users database. WARNING -> destructive operationaggcollects posts for the registered useraddfeedadds a feed for the user. the args should be in the order'title' 'url'. follows the feed for the user afterwardsfollowfollows a feed URL for the currently logged in user if it exists in the databaseunfollowunfollows a feed URL for the currently logged in user if it exists in the databaseregisterregisters a new user. fails if user existsuserslists the registered usersbrowsebrowse recent posts for the currently logged in user. recieves one additional parameter, a number to limit the number of posts shownfeedslist of feed URLs added by the users