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 <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-05-21 20:10:02 +02:00
parent a96b208582
commit 67382bec39
+9
View File
@@ -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);
});