我有以下文件结构:
.
├── bin
│   └── hello
├── pkg
└── src
    └── jacob.uk.com
        ├── greeting
        │   └── greeting.go
        └── helloworld.go
5 directories, 3 files使用以下GOPATH
/Users/clarkj84/Desktop/LearningGo在src文件夹中执行/usr/local/go/bin/go install jacob.uk.com时,我得到错误local import "./greeting" in non-local package
helloworld.go
package main;
import "./greeting"
func main() {
}发布于 2020-09-01 14:05:26
您可以在go 1.11<=中使用replace添加本地包到您的go.mod中,并使用"replace“关键字,如下所示(您不需要创建github存储库,只需像这样添加行)
module github.com/yourAccount/yourModule
go 1.15
require (
    github.com/cosmtrek/air v1.21.2 // indirect
    github.com/creack/pty v1.1.11 // indirect
    github.com/fatih/color v1.9.0 // indirect
    github.com/imdario/mergo v0.3.11 // indirect
    github.com/julienschmidt/httprouter v1.3.0
    github.com/mattn/go-colorable v0.1.7 // indirect
    github.com/pelletier/go-toml v1.8.0 // indirect
    go.uber.org/zap v1.15.0
    golang.org/x/sys v0.0.0-20200831180312-196b9ba8737a // indirect
)
replace (
    github.com/yourAccount/yourModule/localFolder =>"./yourModule/localFolder"
    github.com/yourAccount/yourModule/localFolder =>"./yourModule/localFolder"
)然后在您的main.go =>中
import (
    alog "github.com/yourAccount/yourModule/localFolder"
    slog "github.com/yourAccount/yourModule/localFolder"
)https://stackoverflow.com/questions/30885098
复制相似问题