Rendering static content
In this section, we will learn how to serve the web pages we have created as static content. We will use the standard Go net/http
package to serve up the web pages. All the code and HTML files can be found inside the static/web
directory (https://github.com/PacktPublishing/Full-Stack-Web-Development-with-Go/tree/main/Chapter04/static/web).
Execute the server using the following command:
go run main.go
You will see the following message on the screen:
2022/01/11 22:22:03 Starting up server on port 3333 ...
Open your browser and enter http://localhost:3333
as the URL. You will see the login page, as shown in Figure 4.2:
Figure 4.2 – The login page
To access the dashboard page, you can use the URL http://localhost:3333/dashboard.html
. You will see like the following screenshot:
Figure 4.3 – The dashboard page
Let’s take a quick look at the code that serves up the static...