Last active
February 4, 2023 00:32
-
-
Save rudolph9/dd5e3dbcbf762abdb3f662e39dacfa7f to your computer and use it in GitHub Desktop.
Revisions
-
rudolph9 revised this gist
Sep 6, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ Followed tutorial here: https://github.com/golang/go/wiki/WebAssembly ## Setup 1. install compatible version of golang. Test with go1.12.8 2. get cue: `go get -u cuelang.org/go/cue` NOTE: this installs the packages files, not the cmd 3. get the wasm exec_file `cp "$(go env GOROOT)/misc/wasm/wasm_exec.js` ## Build -
rudolph9 revised this gist
Sep 3, 2019 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -10,11 +10,11 @@ Followed tutorial here: https://github.com/golang/go/wiki/WebAssembly ## Build 4. Build the wasm: `GOARCH=wasm GOOS=js go build -o lib.wasm main.go` ## Serve files 5. install `goexec` if needed (or serve the files some other way): `go get -u github.com/shurcooL/goexec` 5. Serve files: `goexec 'http.ListenAndServe(":8080", http.FileServer(http.Dir(".")))'` -
rudolph9 revised this gist
Sep 3, 2019 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,6 +6,7 @@ Followed tutorial here: https://github.com/golang/go/wiki/WebAssembly 1. install compatible version of golang. Test with go1.12.8 2. get cue: `go get -u go get cuelang.org/go/cue` NOTE: this installs the packages files, not the cmd 3. get the wasm exec_file `cp "$(go env GOROOT)/misc/wasm/wasm_exec.js` ## Build -
rudolph9 created this gist
Sep 2, 2019 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ # Cue Web Assembly Followed tutorial here: https://github.com/golang/go/wiki/WebAssembly ## Setup 1. install compatible version of golang. Test with go1.12.8 2. get cue: `go get -u go get cuelang.org/go/cue` NOTE: this installs the packages files, not the cmd ## Build 3. Build the wasm: `GOARCH=wasm GOOS=js go build -o lib.wasm main.go` ## Serve files 4. install `goexec` if needed (or serve the files some other way): `go get -u github.com/shurcooL/goexec` 5. Serve files: `goexec 'http.ListenAndServe(":8080", http.FileServer(http.Dir(".")))'` This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ <!DOCTYPE html> <!-- Copyright 2018 The Go Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file. --> <html> <head> <meta charset="utf-8" /> <title>Go wasm</title> </head> <body> <script src="wasm_exec.js"></script> <script> if (!WebAssembly.instantiateStreaming) { // polyfill WebAssembly.instantiateStreaming = async (resp, importObject) => { const source = await (await resp).arrayBuffer(); return await WebAssembly.instantiate(source, importObject); }; } const go = new Go(); let mod, inst; WebAssembly.instantiateStreaming(fetch("lib.wasm"), go.importObject).then( result => { mod = result.module; inst = result.instance; document.getElementById("runButton").disabled = false; } ); async function run() { await go.run(inst); inst = await WebAssembly.instantiate(mod, go.importObject); // reset instance } </script> <button onClick="run();" id="runButton" disabled>Run</button> </body> </html> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ package main import ( "fmt" "math/big" "cuelang.org/go/cue" ) func main() { const config = ` TimeSeries: { "2019-09-01T07:00:00Z": 36 } TimeSeries: { "2019-09-01T07:10:59Z": 200 } ` var r cue.Runtime instance, err := r.Compile("test", config) if err != nil { fmt.Println(err) } var bigInt big.Int instance.Lookup("TimeSeries").Lookup("2019-09-01T07:10:59Z").Int(&bigInt) fmt.Println(bigInt.String()) } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ // get this file by running `cp "$(go env GOROOT)/misc/wasm/wasm_exec.js"`