当我试图构建一个我正在处理的go项目时,我得到了以下错误。
cannot find package "github.com/user/projectname/models" in any of:
/usr/local/go/src/github.com/user/projectname/models (from $GOROOT)
/Users/username/go/src/github.com/user/projectname/models (from $GOPATH)此错误使我感到困惑,因为包位于goroot的目录中。我有3个go文件,其中定义了模型。当我在模型目录中运行“go build”或“go install”时,不会返回错误。我是新来的,相信我一定是错过了一些简单的东西。我使用的是mac,我的github用户名目录显示为github.com:user,而不是github.com/username。那会有什么不同吗?
类导入模型片段:
package dal
import (
"database/sql"
"log"
"github.com/user/projectname/models"
)模型类:
package models
import "time"
//Album of an artist.
type Album struct {
ID int `json:"id"`
Title string `json:"title"`
ArtistID int `json:"artist_id"`
ReleaseDate time.Time `json:"date"`
}发布于 2018-04-10 06:03:37
我更改了目录结构,包现在导入。以前,我的文件夹名为src->github.com、github.com/username。此后,我将其修改为src->github.com->username。像这样移动文件夹可以很容易地找到项目。
官方的go文档让人不清楚这是否是预期的结构。然而,看一看github代码布局,它就变得很清楚了。
https://stackoverflow.com/questions/49644039
复制相似问题