Home

Awesome

GWeb: golang + js + wasm

gweb -- strictly typed WebAPI library on top of syscall/js. Like flow or TypeScript but for Go. You need it if you want to interact with browser from wasm-compiled Go program.

Features

Installation

GOOS=js GOARCH=wasm go get github.com/life4/gweb

If you're using VSCode, it's recommend to create a .vscode/settings.json file in your project with the following content:

{
    "go.toolsEnvVars": {
        "GOARCH": "wasm",
        "GOOS": "js",
    },
    "go.testEnvVars": {
        "GOARCH": "wasm",
        "GOOS": "js",
    },
}

Error handling

In the beautiful JS world anything at any time can be null or undefined. Check it when you're not sure:

doc := web.GetWindow().Document()
el := doc.Element("some-element-id")
if el.Type() == js.TypeNull {
    // handle error
}

Missed API

If something is missed, use syscall/js-like methods (Get, Set, Call etc):

doc := web.GetWindow().Document()
el := doc.Element("some-element-id")
name = el.Get("name").String()

Packages

GWeb is a collection of a few packages:

Contributing

Contributions are welcome! GWeb is a Open-Source project and you can help to make it better. Some ideas what can be improved:

And even if you don't have spare time for making PRs, you still can help by talking to your friends and subscribers about GWeb. Thank you :heart:

Similar projects