Skip to content
/ gjs Public

Comprehensive API for Webassembly host environment

License

Notifications You must be signed in to change notification settings

blancsoft/gjs

Repository files navigation

✨ GJS ✨

Comprehensive API for Webassembly environment

Create a fork Github Actions made-with-Go GoReportCard Go.mod version LICENCE Latest release

About

GJS provides a comprehensive API to access the WebAssembly host environment when using the js/wasm architecture. Its API is based on JavaScript semantics and provides WebAssembly interop between Go and JS values. Its current scope is to provide a comprehensive and well-tested API.

Install

GOOS=js GOARCH=wasm go get github.com/chumaumenze/gjs

Usage

package main

import (
	"github.com/chumaumenze/gjs"
)

type Data struct {
	Code    int
	Message string `json:"message"`
	inner   any
}

func main() {
	data := Data{
		Code:    200,
		Message: "Hello World!",
		inner:   "I am ignored",
	}
	_ = gjs.ValueOf(data) // e.g. {Code: 200, "message": "Hello World!"}
}

Motivations

The Go standard library's syscall/js package offers limited compatibility between Go and JavaScript values.

  • The js.Value type lacks support for interfaces or assignment methods for complex Go values.
  • The js.ValueOf function cannot handle complex types like structs, leading to a panic with the error message ValueOf: invalid value.

To overcome these limitations, gjs builds upon and extends the functionality of syscall/js.

About

Comprehensive API for Webassembly host environment

Resources

License

Stars

Watchers

Forks

Packages

No packages published