Summary: lets practice with files and go routines, making a multi-threaded fortune program
Due: Monday Nov 9th at 11:59pm (I'll probably give project4 on that same day)
Create a new project. Make sure it has your name in it somewhere in the project name.
(granted I am pushing the limits to try and get a simple program which also practices with channels and goroutines)
Write go go program that has two functions (which will be compiled to WASM)
Make sure that you have
embedded (using go:embed ) the fortunes.txt file discussed
in the second function below
The main function will
create a channel and then spawn the fortune function as a go routine taking the channel as a parameter.
Listen for a button press from the web page
If the user presses the show fortune button - send a message to the fortune function below
If the user presses the quite button, then end the program.
The fortune function will
Open the fortunes.txt file and read it in.
split the contents of the fortunes file on the %% string to get a slice of strings
loop forever
wait for a message on the channel
when a message is received, randomly select one of the fortunes from your slice
and send it to the dom in the web page.
Using goroutines and channels will feature heavily in this project’s grading
you will need a web page with a web server. The web page needs two buttons, a fortune button and a quite button. They can be in the html or generated by GO. You will need to also have a label or div or some other text to put the fortune onto the web page.
There are several mechanisms that you can use to access the DOM of the web page. Here are two approaches that could work for you:
Include a readme in your project which includes and explains the following
Be sure to include all of the go files, and the html and js files needed to run the wasm program with your project.
Also include the fortunes.txt file
Submit the project by putting it on github and sending me a collaboration invite. As before.