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
main.go (the entry) and geometry.go, both package main. No import is needed between them.
- Run builds the entry together with every other
.gofile in its folder, so they form one program. - Files whose name starts with
mainortest_are left out — each of them is a separate program with its ownmain(). - There is no
go.modand no network: only the standard library can be imported (fmt,strings,sort,math,time,encoding/json, …).go getis not available.