Online Go Compiler
Write, compile, and run Go code in your browser — perfect for learning, practice, and quick validation.
Go Code Editor
Output
Standard Output (stdout)
Standard Error (stderr)
Execution Info
Exit Code:
Run Status:
Usage
- Write Go code in the editor on the left (include
package mainandfunc main()). - Click “Run Code” to compile and execute online.
- The right panel shows program output and errors.
- The green area is standard output (e.g.,
fmt.Println). - The red area shows compile/runtime errors and warnings.
- Execution info includes exit code and run status.
- Shortcut:
Ctrl+Enter(Cmd+Enteron macOS).
Go Basics
Basic Structure:
package main
import "fmt"
func main() {
fmt.Println("Hello, Go!")
}
import "fmt"
func main() {
fmt.Println("Hello, Go!")
}
Common Packages:
fmt- formatted I/Ostrings/strconv- string utilities and conversionssort- sorting utilitiestime- time and schedulingmath- math functions
Types & Collections
Slices & Maps:
nums := []int{3, 7, 1, 9, 4}
m := map[string]int{"alice": 3, "bob": 5}
m := map[string]int{"alice": 3, "bob": 5}
Examples:
for i := 0; i < len(nums); i++ {
fmt.Println(nums[i])
}
for k, v := range m {
fmt.Println(k, v)
}
fmt.Println(nums[i])
}
for k, v := range m {
fmt.Println(k, v)
}
Control Structures
Conditionals & Loops:
n := 7
if n%2 == 0 { fmt.Println("even") } else { fmt.Println("odd") }
for i := 0; i < 3; i++ { fmt.Println(i) }
if n%2 == 0 { fmt.Println("even") } else { fmt.Println("odd") }
for i := 0; i < 3; i++ { fmt.Println(i) }
Functions & Methods
Function Example:
func add(a, b int) int { return a + b }
func main() { fmt.Println(add(2, 3)) }
func main() { fmt.Println(add(2, 3)) }
FAQ
Which Go versions are supported?
Common mainstream Go versions are supported; details depend on the backend environment.
Can I use third-party libraries?
The runtime is sandboxed and external dependencies aren’t supported. Use standard library examples.
Is there a time limit?
Yes. To prevent infinite loops and ensure fair use, compilation and execution are time-limited and will be terminated on timeout.
Can I save code?
Saving online isn’t supported yet. Copy important code locally or use bookmarks/notes to keep snippets.
Is interactive input supported?
Not at the moment. Put test data directly in your code to validate.
Sample Programs (click Run above)
1. Recursive Factorial
package main
import "fmt"
func fact(n int) int { if n <= 1 { return 1 } return n * fact(n-1) }
func main() { fmt.Println("5! =", fact(5)) }
import "fmt"
func fact(n int) int { if n <= 1 { return 1 } return n * fact(n-1) }
func main() { fmt.Println("5! =", fact(5)) }
2. Max of a Slice
package main
import "fmt"
func main() {
nums := []int{3, 7, 1, 9, 4}
maxv := nums[0]
for i := 1; i < len(nums); i++ {
if nums[i] > maxv { maxv = nums[i] }
}
fmt.Println("Maximum:", maxv)
}
import "fmt"
func main() {
nums := []int{3, 7, 1, 9, 4}
maxv := nums[0]
for i := 1; i < len(nums); i++ {
if nums[i] > maxv { maxv = nums[i] }
}
fmt.Println("Maximum:", maxv)
}