project.go:6:2: cannot find package "example.com/project/package" in any of:
/usr/local/Cellar/go/1.1.2/libexec/src/pkg/example.com/project/package (from $GOROOT)
/Users/me/go/src/example.com/project/package (from $GOPATH)
Fetching https://example.com/project/package?go-get=1
ignoring https fetch with status code 404 Fetching http://example.com/project/package?go-get=1
Parsing meta tags from http://example.com/project/package?go-get=1 (status code 404)
import "example.com/project/package": parse http://example.com/project/package?go-get=1: no go-import meta tags
package example.com/project/package: unrecognized import path "example.com/project/package"
Why can't go get/build find the local package. I understand go get will fail on my repo because it's bare, but it seems like go get is completely ignoring the local file, forcing me to commit and push my code before I can compile it. This is, per the snippet, OSX 10.8 and Go 1.1.2 installed via brew. GOPATH is set to /Users/me/go and GOROOT is empty.
I should note that I don't have this problem at all when using go get in gitbash on my Windows machine. I've tried all the google-fu I can think of to search this, but everyone claims you can use relative "project/package" imports, which also completely fail in this case.
Upgrading from go1.1.2 to go1.2 through brew upgrade go
fixed this problem
You can work with code locally without having pushed it - you just need your folder structure to mimic the import path.
Put your library code inside a src/
directory, with a folder structure mimicking the import path:
[15:42] foa:home $ tree
.
├── myprogram.go
└── src
└── example.com
└── project
└── mypackage
└── mypackage.go
Then set GOPATH to the directory that has src/
in it, and you'll be able to build the project:
[15:42] foa:home $ export GOPATH=`pwd`
[15:42] foa:home $ go build
Here's myprogram.go
:
package main
import "example.com/project/mypackage"
func main() {
mypackage.Run()
}
And mypackage.go
:
package mypackage
import "fmt"
func Run() {
fmt.Println("It works.")
}
It's common to lay out your working directories like this, and then root the actual git repositories at the lowest level (e.g. in src/example.com/project/mypackage
) so that they work cleanly with go get
and go install
for other users.