The bookings web application from the Building Modern Web Applications with Go course on Udemy.
The web application provides basic functionality to make reservations and manage reservations. It uses Postgres to store reservations.
Home page:
One of the two available accommodations:
Make reservation:
An administrator dashboard is available to display all reservations:
Reservation calendar:
On Debian Linux, PostgreSQL can be installed with the following command:
# apt-get install postgresql postgresql-doc
Both the default database user and default database are called postgres
By default, Postgres uses a concept called “roles” to handle authentication and authorization. After installation Postgres is set up to use ident authentication, meaning that it associates Postgres roles with a matching Unix/Linux system account.
Use su to swith to the postgres acount and create a user with the same name as the system user:
$ su -
# su -s /bin/bash postgres
postgres@debian:/root$ createuser -s username
The -s option grants superuser privileges.
Next we need to create a database for the user:
postgres@debian:/root$ createdb -O username username
Now try to start psql as a normal user:
$ psql
username=# \q
After setting up a user for the local system user, we no longer need to switch to the postgres account to run postgres commands. Add an bookings postgres user:
$ createuser -P bookings
This creates an istagram user that is not allowed to create new databases or roles and is not superuser. The -P flag will display a password prompt to set a password for the user.
To create the bookings database, run the follwing command:
$ createdb -O bookings bookings
pgAdmin is a popular feature-rich open source database administration tool for PostgreSQL. Follow the instructions on the web site to install it.
On Debian Linux, pgAdmin is installed in /usr/pgadnmin4
. Start pgAdmin and create a new Server by right-clicking on Servers and selecting Create -> Server...
The name should be localhost, switch to the connection tab and enter the required information:
Soda (which is also called Pop) can be used to run SQL migrations.
To install Soda, run the following command:
$ go get github.com/gobuffalo/pop/...
Run soda from the Goland terminal:
$ soda -v
v5.3.1
If the output is soda: command not found
, at it to PATH
.
Copy the database.yml.example
to database.yml
and fill out username and password.
Run the following command to create a migrations file:
$ soda generate fizz CreateUserTable
v5.3.1
DEBU[2021-05-10T11:07:23+02:00] Step: 9bf35aef
DEBU[2021-05-10T11:07:23+02:00] Chdir: /home/johndoe/go/src/bookings
DEBU[2021-05-10T11:07:23+02:00] File: /home/johndoe/go/src/bookings/migrations/20210510090723_create_user_table.up.fizz
DEBU[2021-05-10T11:07:23+02:00] File: /home/johndoe/go/src/bookings/migrations/20210510090723_create_user_table.down.fizz
Run the migration using the following command:
$ soda migrate
pgAdmin should now show the users table:
pgx is a pure Go driver and toolkit for PostgreSQL.
$ go get github.com/jackc/pgx/v4
Go Simple Mail is a Golang package to send email. It support keep alive connection, TLS and SSL.
$ go get github.com/xhit/go-simple-mail/v2
MailHog is an email testing tool for developers
From a terminal run:
$ go get github.com/mailhog/MailHog
Start MailHog by running
$ ~/go/bin/MailHog
Open http://localhost:8025/
in a browser to show the web UI.
Foundation for Emails is a CSS framework to style emails. Download the CSS version.
RoyalUI is a highly responsive template built with the latest version of Bootstrap, CSS, HTML5, jQuery, and SASS that can be used for a dashboard.