gopherjs | A compiler from Go to JavaScript for running Go code | Game Engine library
kandi X-RAY | gopherjs Summary
kandi X-RAY | gopherjs Summary
Nearly everything, including Goroutines (compatibility documentation). Performance is quite good in most cases, see HTML5 game engine benchmark. Cgo is not supported.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of gopherjs
gopherjs Key Features
gopherjs Examples and Code Snippets
Community Discussions
Trending Discussions on gopherjs
QUESTION
ANSWER
Answered 2020-Nov-09 at 09:31GopherJS has been effectively abandoned, and will not be adding support for Go 1.13 or later. That said, there has been some work to support Go 1.13 and 1.14 in some forks. It remains to be seen how much traction a fork is likely to gain moving forward.
You may have some success using one of the unofficial forks, if you really need this to work.
So in summary, your options are:
- Use an unofficial fork of GopherJS which supports Go 1.14 sufficiently for your needs.
- Use an old or backported* version of Vecty which works with Go 1.12 and GopherJS
- Consider using Go/WASM in place of GopherJS.
*You'll likely have to do this backport yourself.
QUESTION
I recently found out that Go compiles down to WebAssembly. Cool!
As per this Go doc, the Go toolchain itself is written in Go.
This made me think, can the Go compiler run in the browser? Can I make a website which given a file path through an upload button (though, without uploading anything), can compile a Go project and return the executable as a "download"?
The end result I'm looking for is an executable file saved to disk, not for the Go code to run in a browser, but I don't need the exact scenario above to be followed as long as that is the final result.
If this is possible, what are the limitations, if any?
Additional resources I have looked at:
- A compiler from Go to WASM on GitHub
- Someone working on a game where entered Go code runs in the browser
EDIT: I have started work on this, based on a similar project. The repo can be found here: https://github.com/TR-SLimey/IBGC
...ANSWER
Answered 2020-Jul-03 at 18:00It is possible, but it's hard to do.
You can't access files using WebAssembly. Instead, you need the user to drop a folder inside the webpage and use the File and Directory Entries API to get the files and their contents.
But the real problem is passing the files from JS to WASM and vice-versa. You'll also need to replace in the compiler source code all the calls to the Go standard library that would access files to calls to JS functions. Those function need to access the WASM memory directly. You will need to modify the compiler quite a bit.
To download the binary, you can create a Blob
, use URL.createObjectURL()
to get an URL to that blob, create an element with
.download = true
and .href =
, and then .click()
it.
The performance might be worse than running the Go compiler directly, but other than that it should work just fine.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install gopherjs
GOPHERJS_GOROOT - if set, GopherJS uses this value as the default GOROOT value, instead of using the system GOROOT as the default GOROOT value
GOPHERJS_SKIP_VERSION_CHECK - if set to true, GopherJS will not check Go version in the GOROOT for compatibility with the GopherJS release. This is primarily useful for testing GopherJS against unreleased versions of Go.
The package github.com/gopherjs/gopherjs/js (see documentation) provides functions for interacting with native JavaScript APIs. For example the line.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page