Displaying sensor data and weather alerts on a Wasm page
Our goal is to develop a small application that displays weather alerts and our sensor data that is being published to an MQTT broker, so we will need some very basic HTML and JavaScript skills in order to achieve this. We start by developing a small server that serves the Wasm app to a client.
Serving the application
As Wasm is served to a browser, we need an HTTP endpoint that serves all files we might need. We start by creating a new folder named wasm-server
inside the Chapter07
folder, and inside this folder we create a new main.go
file with an empty main
function. Now, follow these steps to implement the server:
- Define the directory where the
FileServer
should look for files, as follows:const dir = "Chapter07/html"
- Now, inside the
main
function, create a newFileServer
and pass the directory as a parameter, as follows:fs := http.FileServer(http.Dir(dir))
- Start an HTTP server that listens...