https://github.com/live-codes/go2js
Compile Go to JS in the browser (using Gopherjs)
https://github.com/live-codes/go2js
Last synced: 12 months ago
JSON representation
Compile Go to JS in the browser (using Gopherjs)
- Host: GitHub
- URL: https://github.com/live-codes/go2js
- Owner: live-codes
- License: bsd-2-clause
- Created: 2021-08-19T06:20:34.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-08-30T08:13:42.000Z (almost 2 years ago)
- Last Synced: 2025-06-25T17:06:08.303Z (12 months ago)
- Language: CSS
- Size: 15 MB
- Stars: 6
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go2JS
Compile Go to JS in the browser (using [GopherJS](https://github.com/gopherjs/gopherjs))
Based on [GopherJS Playground](https://github.com/gopherjs/gopherjs.github.io)
The motive for this project was to enable client-side compiling of Golang to JavaScript to run in the browser for [LiveCodes](https://github.com/live-codes/livecodes).
## Usage
UMD:
```html
const code = `
package main
import ("syscall/js"
"fmt")
func main() {fmt.Println("Hello, from Go")
js.Global().Call("alert", "Hello, JavaScript")
println("Hello, JS console")}
`;
window.go2js
.format(code)
.then((formatted) => {
console.log(formatted);
// return window.go2js.compile(formatted, 'https://cdn.jsdelivr.net/npm/@live-codes/go2js/build/');
return window.go2js.compile(formatted);
})
.then(eval)
.catch(console.warn);
```
ESM:
```js
import { compile, format } from 'https://cdn.jsdelivr.net/npm/@live-codes/go2js';
const code = `
package main
import ("syscall/js"
"fmt")
func main() {fmt.Println("Hello, from Go")
js.Global().Call("alert", "Hello, JavaScript")
println("Hello, JS console")}
`;
format(code)
.then((formatted) => {
console.log(formatted);
// return compile(formatted, 'https://cdn.jsdelivr.net/npm/@live-codes/go2js/build/');
return compile(formatted);
})
.then(eval)
.catch(console.warn);
```
Run `npm start` to start a server (http://127.0.0.1:8080) and watch for changes.
## Contribution
Please do!
Feedback, ideas and pull requests are highly appreciated.
## License
[BSD 2-Clause "Simplified" License](LICENSE) same as GopherJS lisence
## Support the author
[](https://ko-fi.com/N4N036P4Y)