Grad Project 3 : WASM fortune fun



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)


Details:


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

  1. create a channel and then spawn the fortune function as a go routine taking the channel as a parameter.

  2. Listen for a button press from the web page

  3. If the user presses the show fortune button - send a message to the fortune function below

  4. If the user presses the quite button, then end the program.


The fortune function will

  1. Open the fortunes.txt file  and read it in.

    1. be sure to use go:embed to embed the file into the final executable
  2. split the contents of the fortunes file on the %% string to get a slice of strings

  3. loop forever

    1. wait for a message on the channel

    2. when a message is received, randomly select one of the fortunes from your slice

    3. 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:


Readme:

Include a readme in your project which includes and explains the following


Submitting the project.

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.