Skip to content
Devtoolry

Go Compiler

Compile and run Go code online with the official Go 1.27 compiler, goroutines and stdin input. It compiles to WebAssembly in your browser, so code stays private.

Something not working, or missing a feature? Send feedback

About the Go Compiler

The online Go Compiler builds your program with the official Go 1.27 compiler and linker and runs it immediately, so you can try generics, goroutines and channels or check an interview answer without installing Go. The toolchain itself runs in your browser as WebAssembly, so your code is never uploaded.

Your code runs in an isolated Web Worker in your browser, so it never leaves your device.

How to use the Go Compiler

  1. Write or paste a Go program with package main and a main() function.
  2. Put any input your program reads from os.Stdin (bufio.Scanner, fmt.Scan) in the stdin box.
  3. Click Run. The first run downloads the Go toolchain (about 23 MB); later runs reuse it.
  4. Fix compiler errors (they show the line and column), then read the output and exit code.

Example

Sum the numbers on standard input

Input

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	sum := 0
	for scanner.Scan() {
		for _, field := range strings.Fields(scanner.Text()) {
			n, err := strconv.Atoi(field)
			if err != nil {
				fmt.Fprintln(os.Stderr, "not a number:", field)
				continue
			}
			sum += n
		}
	}
	fmt.Println("Sum:", sum)
}

Result

Sum: 108

With "4 8 15" and "16 23 42" on two stdin lines. scanner.Scan returns false when the stdin box is used up, which ends the loop.

Common mistakes

  • Unused imports and variables. Go refuses to compile a program with an unused import or local variable ("imported and not used", "declared and not used"). Remove it, or assign the variable to _ while you experiment.
  • Packages that need a network or an operating system. net/http, os/exec and database drivers are not available, and there is no network. Common packages such as fmt, strings, strconv, sort, slices, maps, math, time, sync, regexp and encoding/json are; the compiler names any package it cannot find.
  • Waiting forever. A program whose goroutines all block (an unbuffered channel nobody reads, an empty select{}) stops with Go’s "all goroutines are asleep - deadlock!" error. A loop that never ends is stopped at the time limit.

Works well with the Go Compiler

Frequently asked questions

Which Go version is used?

Go 1.27, the official gc compiler and linker built for WebAssembly. Generics, range over integers and functions, min and max, and the slices and maps packages all work.

Is it the real Go compiler or an interpreter?

The real compiler. Your code is compiled and linked to a WebAssembly binary exactly as go build would do, so compile errors, panics and the deadlock detector behave like they do on your computer.

Do goroutines and channels work?

Yes. Goroutines, channels, select, the sync package and time.Sleep all work. WebAssembly is single-threaded, so goroutines take turns on one thread instead of running in parallel.

Is my code sent to a server?

No. The Go compiler, the linker and your program all run in your browser as WebAssembly, so the code and its input stay on your device.

Can my program read and write files?

Yes, in a temporary in-memory file system: os.WriteFile and os.ReadFile work under /tmp during a run, and everything is gone when the run ends.