Browser-based Go compiler using WebAssembly. Compile and run Go programs entirely in the browser with no server required.
- 🚀 Complete Go toolchain - Compiler, linker, and 340 standard library packages
- 📦 Single file distribution - Everything in one
goscript.packfile (168 MB) - 🌐 Pure browser execution - No backend, no installation
- 📚 Full standard library - fmt, net/http, encoding/json, crypto, and more
- 🔧 Simple API -
GoScript.create(),runCode(),build(), andrun()
<!-- Option A: Bundled (includes wasm_exec.js) -->
<script src="dist/goscript.bundle.js"></script>
<!-- Option B: Separate files -->
<script src="src/wasm_exec.js"></script>
<script src="dist/goscript.js"></script>const gs = await GoScript.create({
packUrl: 'assets/goscript.pack',
stdout: (text) => console.log(text)
});
const result = await gs.runCode(`
package main
import "fmt"
func main() { fmt.Println("Hello from Go!") }
`);
console.log(result.compileTime);Download the latest release:
dist/goscript.bundle.js- SDK + wasm_exec.js (43 KB)assets/goscript.pack- Toolchain (168 MB)
git clone https://github.com/monstercameron/GoScript.git
cd GoScript
npm ci
npm run fetch:pack
npm run buildnpm run fetch:pack downloads docs/assets/goscript.pack from the GitHub release asset for local development.
<script src="https://cdn.example.com/goscript/1.0.0/goscript.bundle.js"></script>npm install goscript-sdkconst gs = new GoScript(options);| Option | Type | Default | Description |
|---|---|---|---|
packUrl |
string |
'assets/goscript.pack' |
URL to the toolchain pack file |
stdout |
function |
console.log |
Callback for program stdout |
stderr |
function |
console.error |
Callback for errors |
progress |
function |
noop |
Callback for progress updates (percentage, message) |
onOutput |
function |
alias | Legacy alias for stdout |
onError |
function |
alias | Legacy alias for stderr |
onProgress |
function |
alias | Legacy alias for progress |
debug |
boolean |
false |
Enable debug logging |
Create and initialize the SDK in one step.
const gs = await GoScript.create({
packUrl: '/assets/goscript.pack'
});Initialize the SDK if needed and return the instance.
await gs.ready();Compile and run Go source in one step. This is the recommended starting point for new integrations.
const result = await gs.runCode(`
package main
import "fmt"
func main() { fmt.Println("Hello!") }
`);Legacy explicit initialization method. ready() or GoScript.create() are usually better starting points.
await gs.init();Compile Go source without running it.
const result = await gs.build('package main\nfunc main() {}');Compatibility alias for explicit compile flow.
// Single file
const result = await gs.compile('package main\nfunc main() {}');
// Multiple files
const result = await gs.compile({
'main.go': 'package main\nfunc main() { hello() }',
'hello.go': 'package main\nimport "fmt"\nfunc hello() { fmt.Println("Hi") }'
});Returns: CompileResult
{
wasm: ArrayBuffer;
compileTime: number; // Milliseconds
size: number; // Bytes
}Execute a compiled WebAssembly binary. If wasm is omitted, the SDK runs the last successful compile result.
await gs.run(compileResult.wasm);Clear the compiled WASM cache for one source input.
await gs.clearCompiledCache('package main\nfunc main() {}');Convenience method to compile and run in one step.
const result = await gs.compileAndRun(`
package main
import "fmt"
func main() { fmt.Println("Hello!") }
`);
console.log(result.success); // trueReturns: CompileAndRunResult
{
success: boolean;
compileResult?: {
wasm: ArrayBuffer;
metadata: {
compileTime: number;
wasmSize: number;
};
};
error?: string;
}Get the current state of the SDK.
const state = gs.getState();
// { initialized: true, compilerReady: true, compiling: false }Get statistics about the loaded toolchain.
const stats = gs.getStats();
// { compilerSize: 41975000, linkerSize: 10970000, packageCount: 340, ... }Check if a standard library package is available.
gs.hasPackage('fmt'); // true
gs.hasPackage('crypto/sha256'); // true
gs.hasPackage('nonexistent'); // falseGet list of all available packages.
const packages = gs.getPackages();
// ['bufio', 'bytes', 'cmp', 'context', 'crypto', ...]Reset the SDK state (clears VFS, keeps toolchain loaded).
gs.reset();const gs = new GoScript();
await gs.init();
const result = await gs.compileAndRun(`
package main
import "fmt"
func main() {
fmt.Println("Hello, World!")
}
`);
console.log(result.success);const gs = new GoScript({
onProgress: (pct, msg) => {
document.getElementById('progress').style.width = pct + '%';
document.getElementById('status').textContent = msg;
},
onOutput: (text) => {
document.getElementById('output').textContent += text;
}
});
await gs.init();const result = await gs.compileAndRun(`
package main
func main() {
fmt.Println("Missing import!")
}
`);
if (!result.success) {
console.error('Compilation or execution failed:', result.error);
}const result = await gs.compile({
'main.go': `
package main
func main() {
PrintMessage()
}
`,
'utils.go': `
package main
import "fmt"
func PrintMessage() {
fmt.Println("Hello from utils!")
}
`
});goscript/
├── assets/
│ └── goscript.pack # Toolchain (compiler + linker + stdlib)
├── dist/
│ ├── goscript.bundle.js # SDK + wasm_exec.js
│ └── goscript.js # SDK only
├── src/
│ ├── platform.js # VFS, fs bridge, cache, toolchain loader
│ ├── engine.js # Compiler pipeline and app runner
│ ├── goscript-sdk.js # Public SDK entry point
│ └── wasm_exec.js # Go WASM runtime
├── tools/
│ ├── build.ps1 # Build script
│ └── pack-toolchain.ps1 # Toolchain packer
├── demo.html # Interactive demo
└── README.md
The goscript.pack file contains everything needed for compilation:
Header:
- "GOSCRIPT" (8 bytes magic)
- Version 2 (uint32)
Section 1 - Compiler:
- Size (uint32)
- compile.wasm data (~40 MB)
Section 2 - Linker:
- Size (uint32)
- link.wasm data (~10 MB)
Section 3 - Package Index:
- Size (uint32)
- JSON array of package names
Section 4 - Standard Library:
- Package count (uint32)
- Index offset (uint64)
- Package data (concatenated .a files)
- Package index (name + offset + size)
- Chrome 57+
- Firefox 53+
- Safari 11+
- Edge 16+
Requires WebAssembly support.
- First load is slow - 168 MB toolchain download (cached after first load)
- Memory intensive - Requires ~512 MB RAM for compilation
- No CGO - Pure Go only, no C bindings
- js/wasm target only - Output runs in browser, not natively
# Clone repository
git clone https://github.com/user/goscript.git
cd goscript
# Build SDK bundle
powershell -File tools/build.ps1
# Pack toolchain (if rebuilding from Go source)
powershell -File tools/pack-toolchain.ps1MIT License
- Go compiler and runtime: The Go Authors (BSD License)
- WebAssembly support: WebAssembly Community Group