Online Go Compiler
Write, compile, and run Go code in the browser, perfect for learning, practice, and quick validation.
Go Code Editor
Output
Standard Output (stdout)
Standard Error (stderr)
Execution Info
Exit Code:
Run Status:
How to Use
- Write Go code in the left editor (include the
package mainandfunc main()entry point). - Click "Run Code" to compile and execute online.
- The right panel displays output and error details.
- The green area shows standard output (for example,
fmt.Printlnoutput). - The red area shows compile/run errors and warnings.
- Execution info includes the exit code and run status.
- Shortcut:
Ctrl+Enter(useCmd+Enteron Mac).
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- Formatting I/Ostrings/strconv- String utilities and conversionssort- Sorting toolstime- 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}
Example:
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?
It typically supports mainstream Go versions; the exact version depends on the backend environment.
Can I use third-party libraries?
The sandboxed runtime currently cannot fetch external dependencies. Use standard library examples instead.
Is there a time limit on execution?
Yes. To prevent infinite loops and ensure fair use, compilation/execution has a time limit and will stop automatically when exceeded.
Can I save my code?
Saving online is not available yet. Copy important code locally or store snippets in your bookmarks/notes.
Does it support interactive input?
Interactive input is not supported at the moment. Place test data directly in your code for validation.
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 Value in 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)
}