// SPDX-License-Identifier: MIT // Copyright (C) 2026 Pooya Parsa // Go: the distro's toolchain (Alpine's go from community, Debian's // golang-go), building and running a small program with `go run`. The // first build compiles the parts of the standard library it uses into // ~/.cache/go-build, so later runs are quicker. import type { TerminalApp } from "../types.ts"; const MAIN = `package main import ( "fmt" "runtime" "sync" ) func main() { fmt.Printf("Hello from Go %s on %s/%s, %d CPU(s)\\n", runtime.Version(), runtime.GOOS, runtime.GOARCH, runtime.NumCPU()) // A few goroutines, summing squares in parallel. const n, workers = 1_000_000, 4 var wg sync.WaitGroup sums := make([]int, workers) for w := range workers { wg.Add(1) go func() { defer wg.Done() for i := w; i < n; i += workers { sums[w] += i * i % 7 } }() } wg.Wait() total := 0 for _, s := range sums { total += s } fmt.Println("goroutines done, sum:", total) } `; export default { id: "go", title: "Go", desc: "The Go toolchain, building and running a small program in the guest", // The Go logo, from Simple Icons (CC0 1.0), slug go. icon: { svg: '', viewBox: "-1.5 -1.5 27 27" }, colors: ["#00add8", "#00384a"], needs: { net: true }, files: { "go.mod": "module hello\n\ngo 1.22\n", "main.go": MAIN, }, packages: { alpine: ["go"], debian: ["golang-go"] }, community: true, commands: [ "echo 'The first run compiles parts of the standard library, so it may take a while; later runs reuse ~/.cache/go-build'", "go version", "go run .", ], } satisfies TerminalApp;