Several files and packages

Split package main over several files in one folder; what the standard library offers without installing anything.

Runs in Zerethon IDE · Go 1.27 Official Go documentation ↗
main.go
package main

import "fmt"

func main() {
	fmt.Println(Area(3, 4))
	fmt.Println(Greeting)
}
geometry.go
package main

const Greeting = "shapes ok"

func Area(width, height int) int {
	return width * height
}

Output

12
shapes ok
Two files in the same folder: main.go (the entry) and geometry.go, both package main. No import is needed between them.
  • Run builds the entry together with every other .go file in its folder, so they form one program.
  • Files whose name starts with main or test_ are left out — each of them is a separate program with its own main().
  • There is no go.mod and no network: only the standard library can be imported (fmt, strings, sort, math, time, encoding/json, …). go get is not available.