If you want to start simple, you may use only one main.go
file.
mkdir simple && cd simple
So we have a working directory.
go mod init simple
That initializes the module named “simple” and creates the file go.mod:
.
└── go.mod
vi main.go
Now we edit a single file - which can be called as you like, but usually is called “main.go”
package main
import (
"fmt"
)
func main() {
fmt.Println("Main")
}
The package named “main” is predefined and has to contain a function named “main”, which will be the starting point for your program.
At this point we do not really use modules, we just have one file.
go run main.go
Output:
Main
Let’s add some more files
See the full source on github.