From 67382bec39491e228811956908ddfe84148e6305 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Thu, 21 May 2020 20:10:02 +0200 Subject: [PATCH] cmd/gogio: [wasm] pass location.hash (if set) to os.Args Allow for specifying command line arguments to webassembly programs through the URI hash (https://example.com/wasm/index.html#args) Signed-off-by: Elias Naur --- cmd/gogio/jsbuild.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cmd/gogio/jsbuild.go b/cmd/gogio/jsbuild.go index 5f84745c..327ef988 100644 --- a/cmd/gogio/jsbuild.go +++ b/cmd/gogio/jsbuild.go @@ -50,6 +50,15 @@ func buildJS(bi *buildInfo) error { } const go = new Go(); + + // Pick up argv from location hash (#args). + var hash = location.hash; + if (hash.length > 0 && hash[0] == '#') { + hash = decodeURIComponent(hash.substr(1)); + go.argv = hash.split(" "); + go.argv.unshift("gio"); // os.Args(0) + } + WebAssembly.instantiateStreaming(fetch("main.wasm"), go.importObject).then((result) => { go.run(result.instance); });