Created
June 2, 2022 17:30
-
-
Save afonsolopez/1b2a2663cac1557acd2abce812f1ba7d to your computer and use it in GitHub Desktop.
Small setup of a Go program, exposing a function to JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "fmt" | |
| "syscall/js" | |
| ) | |
| func main() { | |
| fmt.Println("Hello WASM") | |
| js.Global().Set("runChecker", js.FuncOf(runCheck)) | |
| select {} | |
| } | |
| func runCheck(this js.Value, args []js.Value) interface{} { | |
| return "Hey your string is: " + args[0].String() | |
| } | |
| // Build with "$ GOOS=js GOARCH=wasm go build -o main.wasm" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment