August 2019
Beginner to intermediate
798 pages
17h 2m
English
In this section, we are going to see how a Go program can be compiled into WebAssembly code. The Go code of toWasm.go is the following:
package main
import (
"fmt"
)
func main() {
fmt.Println("Creating WebAssembly code from Go!")
}
The important things to notice here are that there is no sign of WebAssembly in this code and that toWasm.go can be compiled and executed on its own, which means that it has no external dependencies related to WebAssembly.
The last step that you will need to take in order to create the WebAssembly code is executing the following command:
$ GOOS=js GOARCH=wasm go build -o main.wasm toWasm.go $ ls -l total 4760 -rwxr-xr-x 1 mtsouk staff 2430633 Jan 19 21:00 main.wasm -rw-r--r--@ 1 mtsouk staff 100 Jan ...
Read now
Unlock full access