Building a self-contained web application
Luckily, Go is a compiled language, which means that you can create an executable or binary with the needed dependencies, all with a single command, as illustrated here:
go build -o app main.go
Note
You can build an executable for different architectures or platforms (Windows, macOS, Linux, and so on) with GOOS
and GOARCH
environment variables.
The command creates an executable called app
in your current directory. By default, Go uses the name of the application directory for naming the executable. However, you can specify a different name or location for the executable with a -o
flag.
You can now execute the binary with the following command:
./app
The server will start on port 8080
as usual, and you can access the web application from localhost:8080
, as illustrated in the following screenshot:
The application is working as expected because the HTML templates...