我在 main.go 中从非主包运行函数时遇到问题// main.gopackage mainimport test "./tests"func main() { test.Test("hello world")}// (relative to main.go) ./tests/test.gopackage testimport "fmt"func Test(str string) { fmt.Println(str)}输出:build command-line-arguments: cannot find module for path _/c_/Users/Mike/Desktop/random/tests
1 回答

不负相思意
TA贡献1777条经验 获得超10个赞
如果您使用的是 Go 1.16+,请使用 Go 模块:
执行
go mod init projectname
替换为
import test "./tests"
import test "projectname/tests"
- 1 回答
- 0 关注
- 92 浏览
添加回答
举报
0/150
提交
取消