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

如果您使用Go 1.16+,请使用Go模块:

  1. 执行go mod init projectname
  2. import test "./tests"替换为import test "projectname/tests"

最新更新