• Stars
    star
    145
  • Rank 254,144 (Top 6 %)
  • Language
    Go
  • License
    MIT License
  • Created over 6 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Compiles Go to WASM and deploys to the jsgo.io CDN

wasmgo

The wasmgo command compiles Go to WASM, and serves the binary locally or deploys to the jsgo.io CDN.

Install

go get -u github.com/dave/wasmgo

Serve command

wasmgo serve [flags] [package]

Serves the WASM with a local web server (default to port 8080). Refresh the browser to recompile.

Deploy command

wasmgo deploy [flags] [package]

Deploys the WASM to the jsgo.io CDN.

Global flags

-b, --build string     Build tags to pass to the go build command.
-c, --command string   Name of the go command. (default "go")
-f, --flags string     Flags to pass to the go build command.
-h, --help             help for wasmgo
-i, --index string     Specify the index page template. Variables: Script, Loader, Binary. (default "index.wasmgo.html")
-o, --open             Open the page in a browser. (default true)
-v, --verbose          Show detailed status messages.

Deploy flags

-j, --json              Return all template variables as a json blob from the deploy command.
-t, --template string   Template defining the output returned by the deploy command. Variables: Page, Script, Loader, Binary. (default "{{ .Page }}")

Serve flags

-p, --port int   Server port. (default 8080)

Package

Omit the package argument to use the code in the current directory.

Examples

Here's a simple hello world:

wasmgo serve github.com/dave/wasmgo/helloworld

The page (http://localhost:8080/) opens in a browser.

Here's an amazing 2048 clone from hajimehoshi:

go get -u github.com/hajimehoshi/ebiten/examples/2048/...
wasmgo deploy -b=example github.com/hajimehoshi/ebiten/examples/2048

The deployed page opens in a browser.

Index

You may specify a custom index page by including index.wasmgo.html in your project or by using the index command line flag.

Your index page should look something like this:

<html>
<head><meta charset="utf-8"></head>
<body>
	<script src="{{ .Script }}"></script>
	<script src="{{ .Loader }}"></script>
</body>
</html>

Template variables

The index page template and the -t flag are both Go templates with several variables available:

  • Page
    The URL of the page on jsgo.io (deploy command output only).

  • Script
    To load and execute a WASM binary, a some JS bootstap code is required. The wasmgo command uses a minified version of the example in the official Go repo. The URL of this script is the Script template variable.

  • Loader
    The loader JS is a simple script that loads and executes the WASM binary. It's based on the example in the official Go repo, but simplified to execute the program immediately instead. The URL of this script is the Loader template variable.

  • Binary
    The URL of the WASM binary file.

Static files

Unfortunately wasmgo does not host your static files. I recommend using rawgit.com to serve static files.

Package splitting

The wasmgo deploy can't yet split the binary output by Go package, can you help?

More Repositories

1

jennifer

Jennifer is a code generator for Go
Go
3,055
star
2

dst

Decorated Syntax Tree - manipulate Go source with perfect fidelity.
Go
1,165
star
3

jsgo

GopherJS compiler, serving framework and CDN.
Go
267
star
4

blast

Blast is a simple tool for API load testing and batch jobs
Go
213
star
5

courtney

Courtney is a coverage tool for Go
Go
150
star
6

rebecca

Rebecca is a readme generator for Go
Go
111
star
7

play

jsgo playground: edit and run Go code in the browser, supporting arbitrary import paths
Go
50
star
8

brenda

Brenda is a boolean expression solver for Go AST
Go
44
star
9

html2vecty

Translate html to vecty syntax
Go
12
star
10

asm

High level assembly DSL
Go
8
star
11

forky

A tool to automate forking and modifying codebases
Go
7
star
12

services

Services for interacting with remote services (gcs, git, http etc.) shared between jsgo, play and frizz.
Go
7
star
13

youtube

Tool to upload videos directly from Google Drive to YouTube
Go
6
star
14

govpn

Go
5
star
15

libify

Convert any Go command line app into a library
Go
5
star
16

dropper

GopherJS package to accept files by drag+drop
Go
5
star
17

gpx

Quick util to manipulate GPX files
Go
4
star
18

flux

Vecty flux library
Go
4
star
19

stablegob

Fork of encoding/gob, with deterministic binary output
Go
4
star
20

dontstayin

I created dontstayin.com back in 2003. We peaked in 2005 with 10 employees, 1.5m uniques & 50m page views per month. We sold the company in 2009 and it was shut down by the new owners in 2012. You can see a documentary filmed in the early days here: https://vimeo.com/24485226. The code is here purely for posterity - it is filled with horrors.
C#
4
star
21

golib

Go
3
star
22

jast

jast is an experimental tool for converting AST to jennifer
Go
2
star
23

patsy

Patsy is a package helper for Go.
Go
2
star
24

kerr

Go errors, but a bit more testable
Go
2
star
25

gopackages

Go utils for for package paths, package names and file paths
Go
2
star
26

sorter

Simplify sorting in Go
Go
2
star
27

frizz

The frizz editor - not ready for public consumption yet
Go
2
star
28

groupshare

Group Share
Dart
2
star
29

astrid

Astrid is a collection of AST utilities for Go
Go
2
star
30

splitter

GopherJS wrapper for Split.js
Go
1
star
31

img

Compress image files in the browser with GopherJS - jsgo.io/dave/img
Go
1
star
32

protod

Protocol Buffer Deltas
Dart
1
star
33

iot

Go
1
star
34

saver

GopherJS package to save files using the FileSaver.js library
Go
1
star
35

dbcombo

DbCombo was mildly successful when I launched in 2001, but it was shut down and deleted in about 2006. I was amazed to find we still have an active user in 2017!
C#
1
star
36

geny

A code generator for Go
Go
1
star
37

refreshable_reorderable_list

A fork of ReorderableList which adds the physics property needed for RefreshIndicator to work
Dart
1
star
38

cfag-server

Dockerfile
1
star
39

oak

A generic CMS in Meteor
JavaScript
1
star
40

scrapy

Web scraper test project
Go
1
star
41

wildernessprime

CSS
1
star