Go Playground
Write, run and debug real Go 1.26 in your browser, with completion and live errors, even offline.
Runs in your browser — nothing is uploaded
Hints
Show solution
Press Debug to record a run, then step through it.
Call stack
Variables
| Name | Type | Value |
|---|
Output so far
Real Go, in the page
This playground runs the official Go compiler and linker, compiled to WebAssembly, inside your browser. Your program is built into a WebAssembly binary and executed right here, so the language is exactly the Go you write everywhere else: structs and methods, interfaces, generics with constraints, closures, goroutines and channels, select with timeouts, defer, panic and recover, and iterators written with iter.Seq.
Each run builds and starts your program from scratch, so package-level variables start over every time. Output appears as it is written, and Stop ends even a program that loops forever.
Errors, completion and gofmt as you type
Your code is type-checked continuously with go/types, the same checker Go's tools use. Mistakes are underlined with Go's own messages — declared and not used, mismatched types, a missing return — and if you press Run with errors, the output lists them in the familiar ./main.go:line:column form and nothing runs.
Type a dot after a package or a value and completion lists its functions, fields and methods with their signatures, including methods promoted from embedded structs. Format runs gofmt, so your code always looks the way Go code is meant to look.
Built for learning and practice
Use it to learn Go from scratch, try an idea, check how a standard-library function behaves or practise for an interview without installing anything. The Examples menu walks through the essentials — slices and maps, structs and interfaces, errors and wrapping, generics, goroutines, channels and select, defer and recover, iterators, closures and sorting — and every example is a starting point for your own code. When a program panics you see Go's real panic message and a stack trace pointing at the exact lines of your code.
The Debug button records a run so you can step through it line by line, forwards and backwards, watching variables, the call stack and goroutines change.
Practise with exercises
There are 45 exercises in four groups. Beginner ones cover loops, slices, maps, strings and runes, and multiple results. Intermediate ones cover structs and methods, pointer receivers, interfaces, fmt.Stringer, custom errors, closures, defer and recover, sorting and generics. Advanced ones cover a generic stack, a worker pool, channel pipelines, select with timeouts, sync.Mutex, iter.Seq iterators and an error-handling bank account. The Interview group has 20 classic problems in Easy, Medium and Hard, from two sum and valid parentheses to an LRU cache, course scheduling, Dijkstra's shortest paths and edit distance.
Check runs hidden Go tests against your code and lists every test and subtest as ✓ or ✗ with its message. Interview problems state the complexity to aim for, and 12 of the 20 have a timing test on a large input that rejects an answer of the wrong complexity with a "Too slow" message. The timing check has a wide margin, so it catches the wrong complexity class, not small differences in speed — the exercises are for practice, not a proctored test. Solved exercises get a tick, and your code and progress stay in this browser.
How to use
- Type or paste Go, or pick an example.
- Watch errors underline as you type; use Ctrl+Space for completion and Shift+Alt+F to format.
- Press Run (Ctrl/⌘+Enter in the editor) to compile and see the output.
- Press Debug to record a run, then step forwards and backwards (F10 / Shift+F10), set breakpoints in the gutter and watch variables and goroutines change.
- Open Exercises to practise with 45 exercises, including 20 interview problems: read the task, write the function, and press Check to run its tests — every test shows ✓ or ✗ with Go's own failure message.
FAQ
Is this the real Go compiler?
Yes. It is the official Go toolchain — the same compile and link commands that go build runs — built for WebAssembly and running in your browser. Your program is compiled into a real WebAssembly binary and run against Go's own standard library and runtime, so goroutines, channels, select, defer and panics behave exactly as they do on your machine, and the error messages are the ones go build prints.
Which Go version?
Go 1.26, including generics, range-over-func iterators, the min and max builtins, range over integers and per-iteration loop variables. The status bar shows the exact version once the toolchain has loaded.
Does it work offline?
Yes, after one visit. The first time you open the page your browser downloads the Go toolchain and standard library, about 20 MB, and keeps them. From then on the editor, completion, errors and running all work with no connection. The status bar shows "Available offline" once everything is stored.
Is my code uploaded?
No. Your code is compiled and run in a background worker inside this browser tab, and saved only in your browser's local storage so it survives a reload. Programs run in a sandbox with no network and no file system, so they can't send your data anywhere.
Which packages can I import?
The commonly used parts of the standard library: fmt, strings, strconv, bytes, bufio, errors, sort, slices, maps, math, math/big, math/rand, time, sync, context, unicode, container/heap and list, encoding/json, csv, base64 and hex, regexp, text/template, iter, crypto hashes, testing and more. Packages that need a network or operating system, such as net/http or os/exec, and third-party modules are not available; the editor says so as soon as you import one.
How do I read input?
Type the lines into the stdin box before you press Run. bufio.Scanner, fmt.Scan and os.Stdin read from it, and when the lines run out they see end of input, exactly as a program does at the end of a file. What your program reads is echoed into the output, like a terminal.
Do goroutines and time.Sleep work?
Yes. Goroutines, channels, select, sync.WaitGroup, mutexes, timers and time.Sleep all work, scheduled by Go's own runtime. A program whose goroutines all block gets Go's real "all goroutines are asleep - deadlock!" error, and Stop ends a program that never finishes.
How does the debugger work?
Press Debug and the playground records your program as it runs, up to 10,000 steps, then lets you replay it: step forwards and backwards, jump between breakpoints set in the gutter, and see the call stack, each frame's variables (changed values are highlighted), return values, which goroutine ran each step, and the output so far. Values are summarised without calling your String or Error methods, so recording never changes what your program prints.
How do the exercises work?
Pick one of 45 exercises: 25 that practise Go itself, from loops and maps to generics, goroutines and iterators, and 20 classic interview problems, from two sum to Dijkstra's shortest paths. Each has a short task, starter code, hints and a reference solution. Check runs hidden tests written with Go's testing package against your code — the same way go test does — and lists every test and subtest as passed or failed with its message. Twelve of the 20 interview problems also time your answer on a large input, so an answer of the wrong complexity class fails with a "Too slow" message that names the complexity to aim for. The timing check has a wide margin, so it catches the wrong complexity class, not small differences in speed or a slow device — the exercises are for practice, not a proctored test. Solved exercises get a tick, and your code for each one is saved in this browser, so you can come back to it later, even offline.