猿问

golang: 构建命令行参数: 找不到路径 x 的模块

我在 main.go 中从非主包运行函数时遇到问题


// main.go

package main


import test "./tests"


func main() {

    test.Test("hello world")

}



// (relative to main.go) ./tests/test.go

package test


import "fmt"


func Test(str string) {

    fmt.Println(str)

}

输出:build command-line-arguments: cannot find module for path _/c_/Users/Mike/Desktop/random/tests 


拉莫斯之舞
浏览 93回答 1
1回答

不负相思意

如果您使用的是 Go 1.16+,请使用 Go 模块:执行go mod init projectname替换为import test "./tests"import test "projectname/tests"
随时随地看视频慕课网APP

相关分类

Go
我要回答