package main
import "fmt"

func main() {
    fmt.Println("Hello World")
}

About This Go Editor

Go was designed at Google for large teams building network services, and almost every decision follows from that: fast compilation, one obvious way to do things, a formatter nobody argues with, and concurrency built into the language rather than bolted on through a library.

The editor highlights goroutines, channels, interfaces and struct tags. Go code is conventionally gofmt-formatted with tabs, which the editor preserves.

Go syntax reference

Go syntax reference
Syntax What it does
x := 42 Short declaration with inferred type. Only inside functions.
func f(a int) (int, error) Multiple return values - the basis of Go error handling.
if err != nil { return nil, err } The idiom. Explicit, repetitive, and deliberately so.
defer file.Close() Runs when the function returns, in LIFO order.
go worker(ch) Starts a goroutine - a lightweight thread managed by the runtime.
ch := make(chan int, 10) Buffered channel. Unbuffered channels synchronise sender and receiver.
type Reader interface { Read(p []byte) (int, error) } Interfaces are satisfied implicitly - no implements keyword.
func Map[T, U any](s []T, f func(T) U) []U Generics, added in Go 1.18.

Go-specific traps

  • Slices share their backing array. append may or may not allocate, so two slices can alias the same memory. Copy explicitly when you need independence.
  • nil interface is not nil. An interface holding a nil pointer is itself non-nil, which is why err != nil can be true when the underlying pointer is nil. Never return a concrete nil pointer as an error.
  • Loop variable capture. Before Go 1.22 the loop variable was reused across iterations, so a goroutine capturing it saw the final value. Go 1.22 changed this - but a lot of code and advice predates it.
  • Unhandled goroutines leak. A goroutine blocked on a channel nobody writes to lives forever. Use context for cancellation.
  • Maps have no defined iteration order, deliberately randomised so nobody depends on one.

Your Code Never Leaves Your Browser

The editor is JavaScript running in this tab. Nothing you type is posted to a server, stored, logged or associated with you, and there is no account and no autosave. That makes it safe to paste a snippet from a private codebase in order to read it with highlighting. The trade-off is that nothing persists either — refresh the page and your content is gone, so copy anything you want to keep.

Frequently Asked Questions

Can I run Go code here?

No - compiling needs the Go toolchain, and nothing on this page executes code. It is an editor for reading and formatting a snippet.

Why does Go not have exceptions?

By design. Explicit error returns make failure paths visible at every call site, at the cost of verbosity. panic and recover exist for genuinely unrecoverable situations, not for ordinary control flow.

What is the difference between a goroutine and a thread?

A goroutine is scheduled by the Go runtime onto a small pool of OS threads and starts with a few kilobytes of stack that grows as needed. Creating hundreds of thousands of goroutines is normal; creating hundreds of thousands of OS threads is not.

Editors for Other Languages

Same editor, configured for a different language, each with its own syntax reference.