duandai6373 2018-04-04 06:15
浏览 25
已采纳

去找不到我的本地包裹

I am getting the following error when trying to build a go project I am working on.

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)

This error is confusing me as the package is located in the directory from goroot. I have 3 go files there with models defined in them. When I run 'go build' or 'go install' in the models directory, no errors are returned. I am new to go and believe I must be missing something simple. I am using a mac and my github username directory shows up as github.com:user instead of github.com/username. Could that make a difference?

Class to import model snippet:

package dal

import (
    "database/sql"
    "log"

    "github.com/user/projectname/models"
)

Model class:

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"`
}

Directory Setup

  • 写回答

1条回答 默认 最新

  • dongpochi9741 2018-04-10 06:03
    关注

    I changed my directory structure and the package now imports. Previously, my folders were named as followed src->github.com, github.com/username. I have since reworked it to src->github.com->username. Moving the folders like this allows the project to be found easily.

    The official go documentation makes it unclear that this is the intended structure. However, upon looking at the github code layout it becomes clear.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)