Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/danieljoos/go-wasm-examples
Some small examples of using Go and WebAssembly
https://github.com/danieljoos/go-wasm-examples
example golang wasm webassembly
Last synced: 2 months ago
JSON representation
Some small examples of using Go and WebAssembly
- Host: GitHub
- URL: https://github.com/danieljoos/go-wasm-examples
- Owner: danieljoos
- Created: 2018-07-06T12:59:03.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-08-20T06:31:42.000Z (over 5 years ago)
- Last Synced: 2024-01-24T03:13:29.600Z (12 months ago)
- Topics: example, golang, wasm, webassembly
- Language: Go
- Size: 11.7 KB
- Stars: 36
- Watchers: 3
- Forks: 8
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# go-wasm-examples
Some small examples of using Go and WebAssemblyThe examples require at least **Go version 1.12**!
# Usage
The `server` directory contains a very small HTTP server implementation that
simply hosts the files of the current working directory.
It also downloads the `wasm_exec.js` JavaScript bridge from the official golang
repository, if the file doesn't already exist.```bash
go build -o server.bin ./server
./server.bin
```
You can also use any other web-server that provides static file hosting.## Example 1:
The first example prints a "Hello World" to the console of the browser.
Browse to http://localhost:3000 after building the example:```bash
GOARCH=wasm GOOS=js go build -o test.wasm ./wasm1
```## Example 2:
The second example interacts with the DOM of the page and enables the "Stop"
button.
It also registers a click handler on the button and keeps the go program alive
until the button was pressed.
Browse to http://localhost:3000 after building the example:```bash
GOARCH=wasm GOOS=js go build -o test.wasm ./wasm2
```## Example 3:
The third example shows how to create elements in the DOM. It uses the
`github.com/PaulRosset/go-hacknews` package to fetch the top 10 stories from
Hacker News and displays them as list of anchors in the DOM.
Browse to http://localhost:3000 after building the example:```bash
go get -u github.com/PaulRosset/go-hacknews
GOARCH=wasm GOOS=js go build -o test.wasm ./wasm3
```## Example 4:
The fourth example implements a very simple markdown editor that uses the
package `github.com/shurcooL/github_flavored_markdown` to render
github-flavoured markdown to HTML.
Browse to http://localhost:3000 after building the example:```bash
go get -u github.com/shurcooL/github_flavored_markdown
GOARCH=wasm GOOS=js go build -o test.wasm ./wasm4
```