2021-03-21 07:41:36 +07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"syscall/js"
|
|
|
|
)
|
|
|
|
|
2021-03-22 04:47:32 +07:00
|
|
|
const hello = "Hello!"
|
|
|
|
|
|
|
|
// helloName's first value is JavaScript's `this`.
|
|
|
|
// However, the way that the JS bridge is written, it will always be JavaScript's undefined.
|
|
|
|
//
|
|
|
|
// If returning a non-nil error value, the resulting promise will be rejected by API consumers.
|
|
|
|
// The rejected value will JavaScript's Error, with the message being the go error's message.
|
|
|
|
//
|
2021-03-22 06:46:19 +07:00
|
|
|
// See other examples which use the Go WASM bridge api, which show more flexibility and type safety when interacting
|
2021-03-22 04:47:32 +07:00
|
|
|
// with JavaScript.
|
|
|
|
func helloName(_ js.Value, args []js.Value) (interface{}, error) {
|
|
|
|
return fmt.Sprintf("Hello, %s!", args[0].String()), nil
|
2021-03-21 07:41:36 +07:00
|
|
|
}
|
|
|
|
|
2021-03-22 04:47:32 +07:00
|
|
|
func main() {
|
|
|
|
fmt.Println("go-mod-wasm initialized")
|
2021-03-21 07:41:36 +07:00
|
|
|
|
2021-03-22 04:47:32 +07:00
|
|
|
setFunc("helloName", helloName)
|
|
|
|
setValue("hello", hello)
|
|
|
|
ready()
|
2021-03-21 07:41:36 +07:00
|
|
|
}
|