我在 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)
}
Run Code Online (Sandbox Code Playgroud)
输出:
build command-line-arguments: cannot find module for path _/c_/Users/Mike/Desktop/random/tests
如果您使用 Go 1.16+,请使用 Go 模块:
go mod init projectname
import test "./tests"
为
import test "projectname/tests"
归档时间: |
|
查看次数: |
2803 次 |
最近记录: |