Skip to content

Commit 3731d0e

Browse files
committed
chore: jsonpath
1 parent 9256cc4 commit 3731d0e

File tree

5 files changed

+43
-1
lines changed

5 files changed

+43
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
.idea
1+
.idea
2+
dist

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
SOURCE=$(shell find . -iname "*.go")
3+
4+
5+
6+
dist/lib.wasm: $(SOURCE)
7+
mkdir -p dist
8+
rm -f dist/*
9+
cp "$(shell go env GOROOT)/misc/wasm/wasm_exec.js" dist/wasm_exec.js
10+
GOOS=js GOARCH=wasm go build -ldflags="-s -w" -o ./dist/lib.wasm cmd/wasm/main.go

cmd/wasm/main.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//go:build js && wasm
2+
3+
package pkg
4+
5+
import (
6+
"github.com/speakeasy-api/jsonpath/pkg"
7+
"syscall/js"
8+
)
9+
10+
func jsFuncWrapper() js.Func {
11+
return js.FuncOf(func(this js.Value, args []js.Value) interface{} {
12+
if len(args) != 2 {
13+
return `{"err":""}`
14+
}
15+
originalYAML := args[0].String()
16+
jsonpath := args[1].String()
17+
returnValue := pkg.Entry(originalYAML, jsonpath)
18+
return returnValue
19+
})
20+
}
21+
22+
func main() {
23+
js.Global().Set("JSONPath", jsFuncWrapper())
24+
<-make(chan bool)
25+
}

pkg/entry.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package pkg
2+
3+
func Entry(yaml string, jsonpath string) string {
4+
return "Hello World"
5+
}

pkg/parser.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package pkg

0 commit comments

Comments
 (0)