xxx为项目名,会生成go.mod文件
go mod init xxx
或直接复制一份go.mod文件
module xxx
go 1.16
// 文件路径
--- main.go
--- go.mod
--- first_module
--- test.go
其中,test.go命名无所谓
// main.go
package main
import (
"fmt"
"xxx/first_module"
)
func main() {
first_module.SayHello()
}
// test.go
package first_module
import "fmt"
func SayHello() {
fmt.Println("hello world")
}