Giter Site home page Giter Site logo

go-wasm-examples's Introduction

go-wasm-examples

Some small examples of using Go and WebAssembly

The 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.

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:

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:

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:

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:

go get -u github.com/shurcooL/github_flavored_markdown
GOARCH=wasm GOOS=js go build -o test.wasm ./wasm4

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.