我是一名Go语言新手,正在处理一个需要本地化的示例代码。
在原始的main.go
导入语句中,它是这样的:
import (
"log"
"net/http"
"github.com/foo/bar/myapp/common"
"github.com/foo/bar/myapp/routers"
)
现在我在/home/me/go/src/myapp
中有common
和routers
包。
所以我将导入语句转换为:
import (
"log"
"net/http"
"./common"
"./routers"
)
但是当我运行go install myapp
时,会出现以下错误:
can't load package: /home/me/go/src/myapp/main.go:7:3: local import "./common" in non-local package
另外,当我在导入语句中使用 common
和 routers
代替 ./common
和 ./routers
时,会出现以下问题:
myapp/main.go:7:3: cannot find package "common" in any of:
/usr/local/go/src/common (from $GOROOT)
/home/me/go/src/common (from $GOPATH)
myapp/main.go:8:2: cannot find package "routers" in any of:
/usr/local/go/src/routers (from $GOROOT)
/home/me/go/src/routers (from $GOPATH)
我该如何修复这个问题?