Your First Program
Hello, World
Section titled “Hello, World”Create a folder and initialize a module — this is the Go equivalent of npm init or cargo init:
mkdir hello && cd hellogo mod init example.com/helloThis creates a go.mod file that names your module and tracks its dependencies. Now create main.go:
package main
import "fmt"
func main() { fmt.Println("Hello, nasigolang!")}Every executable Go program needs a package main and a func main() — that’s the entry point. Run it directly with:
go run main.goBuilding a binary
Section titled “Building a binary”go run compiles and executes in one step, which is great for development. To ship something, compile a standalone binary:
go build -o hello ../helloThe result is a statically linked binary with no runtime dependencies — you can copy it to another machine (same OS/arch) and it just runs. This is one of the reasons Go is popular for CLI tools and infrastructure software.
Anatomy of the program
Section titled “Anatomy of the program”package maindeclares this file belongs to themainpackage, the one Go treats as an entry point.import "fmt"pulls in the standard library’s formatted I/O package.func main()is called automatically when the binary starts. No arguments, no return value.