Go语言进入项目实战阶段,有了更多的需要处理的问题。
Go版本:1.16.5,从建一个空白项目开始
1、创建一个项目,新建一个package文件,文件名module1.go,只有一个方法init
2、在项目目录下执行
go mod init test
3、新建一个main.go文件,内容如下
package main
import (
"fmt"
module1 "test/module1"
)
func main() {
fmt.Println("process start")
module1.Init()
}
4、注意这个go mod init test需和test/module1需保持一致,否则的话会提示找不到package.也就是
module1 "test/module1"这句话是以go mod 命名test为根节点的路径,不是相对main.go的路径。