How to Create Your Own Package in Go

Initialize a Go module with go mod init and write your code in a .go file to create a package.

Create a new directory for your module, initialize it with go mod init, and write your code in a .go file.

mkdir my-package
cd my-package
go mod init github.com/yourusername/my-package
echo 'package main\n\nimport "fmt"\n\nfunc main() { fmt.Println("Hello") }' > main.go
go build

This creates a module named my-package with a single executable.