Skip to content

▶️ Starting point for Go WebAssembly programs processing a user-selected file and rendering the result with a template.

Notifications You must be signed in to change notification settings

efskap/wasm-fileprocessing-starter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go WebAssembly File Processing Starter

This is a starting point for an imo not-so-uncommon use of WebAssembly: having the user select a file, processing it, and then rendering a template based on the result, all inside the browser. For example, I'm working on something like that for parsing Warcraft 3 replays.

In this case, we print the length of the file and the first line if the contents are a valid UTF-8 string.

It embeds the template inside the binary using github.com/jerblack/statics (or rather my 1-commit-ahead fork), and defers file processing until the WebAssembly program has initialized.

Trying it out

Run make in the root directory to build, and serve the public/ directory with something like:

# install goexec: go get -u github.com/shurcooL/goexec
$ goexec 'http.ListenAndServe(`:8080`, http.FileServer(http.Dir(`.`)))'

Make sure the server supports the application/wasm Content-Type. Then you can deploy the folder on some static host/cdn like netlify.

Also take a look at this rather helpful overview: https://github.com/golang/go/wiki/WebAssembly

About

▶️ Starting point for Go WebAssembly programs processing a user-selected file and rendering the result with a template.

Resources

Stars

Watchers

Forks