Skip to content

Commit

Permalink
feat: set js variable from golang
Browse files Browse the repository at this point in the history
  • Loading branch information
mukezhz committed Dec 19, 2023
1 parent 387d5d5 commit b0d8630
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 5 additions & 1 deletion wasm/hello_world/assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<title>WASM HELLO WORLD</title>
</head>
<body>
<h1>WebAssembly using GoLang</h1>
<h1>WebAssembly using :</h1>
<script src="wasm_exec.js"></script>
<script>
async function run() {
Expand All @@ -16,6 +16,10 @@ <h1>WebAssembly using GoLang</h1>
go.importObject
);
go.run(result.instance);

const heading = document.getElementsByTagName("h1")[0];
const originalText = heading.innerText;
heading.innerText = originalText + " " + window?.goLang;
}
run();
</script>
Expand Down
2 changes: 2 additions & 0 deletions wasm/hello_world/cmd/wasm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package main

import (
"fmt"
"syscall/js"
)

func main() {
fmt.Println("Hello world from Go Web Assembly")
js.Global().Set("goLang", "Go Lang")
}

0 comments on commit b0d8630

Please sign in to comment.