go-wasm/examples/http-caller/main.go

36 lines
561 B
Go
Raw Normal View History

2019-09-23 23:22:23 +03:00
package main
import (
"context"
"log"
"github.com/vedhavyas/go-wasm"
)
func main() {
b, err := wasm.BridgeFromFile("test", "./examples/http/main.wasm", nil)
if err != nil {
panic(err)
}
ctx, canc := context.WithCancel(context.Background())
defer canc()
init := make(chan error)
go b.Run(ctx, init)
if err := <-init; err != nil {
panic(err)
}
res, err := b.CallFunc("call", []interface{}{"https://google.com"})
if err != nil {
panic(err)
}
str, err := wasm.String(res)
if err != nil {
panic(err)
}
log.Println("Result:", str)
}