1.12如何导入相对路径模块。
例如
demo_project
- main.go
-- demo
- demo.go
demo.go:
pakcage demo
...
我尝试在main.go中导入“./demo”,但报告错误消息:
找不到路径_ / home / xxx / mywork / go_project / grpc_demo / demo的模块
如何在main.go中导入演示
最佳答案
debug@ulab:/tmp/test$ go run main.go
main.go:3:8: cannot find package "mylib" in any of:
/home/debug/.golang/go/src/mylib (from $GOROOT)
/home/debug/.golang/gopath/src/mylib (from $GOPATH)
$ tree
.
├── main.go
├── src
│ └── hello
│ └── hello.go
└── start.sh
2 directories, 3 files
$ cat start.sh
#!/bin/sh
GOPATH="$(pwd):$(go env GOPATH)"
go run main.go
$ ./start.sh
Welcome to golang
关于go - golang 1.12导入相对目录模块,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55095295/