Sure thing, Richard.
The gist here is that I'd like to leverage the `js` tags to convert a struct TO js.Object, in order to hand off data to JavaScript code. That and I would love to use an API function to do this job; the code below uses a javascript function "trampoline" instead.
The code below helps spell out the best I could figure out by reading the documentation and the codebase. I can get the struct in a JavaScript function call, but it uses the exported struct field names instead:
http://www.gopherjs.org/playground/#/wjNXKc7L0Opackage main
import (
"fmt"
"
github.com/gopherjs/gopherjs/js"
)
type Foo struct {
Value string `js:"xyz"`
}
func main() {
converter := js.Global.Call("eval", `(
function(x) { return x; }
)`)
foo := Foo { Value: "hello world" }
fooObj := converter.Invoke(foo)
fmt.Println("
foo.xyz", fooObj.Get("xyz"))
fmt.Println("foo.Value", fooObj.Get("Value"))
}
//////////////
foo.xyz undefined
foo.Value hello world