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