0

My question is quite similar to this,different is I have directory hierarchy as best answer pointed out,but I still get same problem,why?

$ echo $GOROOT
/usr/local/go

$ echo $GOPATH
/home/mitchell/go

$ cat /home/mitchell/go/src/main.go
package main
import "comment/create"
func main() { }

$ cat /home/mitchell/go/src/comment/create/***.go(bunch of go files)
package create

$ go build main.go
main.go:3:8: import "comment/create": cannot find package
Community
  • 1
  • 1
Alex Luya
  • 9,412
  • 15
  • 59
  • 91
  • 1
    It works in my computer. I suggest to run `go env` and `go build -x main.go` to get more clues. – Nico Feb 22 '14 at 10:13
  • maybe the permissions? put the output of the go build – mcuadros Feb 22 '14 at 11:17
  • `main.go` should be in `src/comment/main.go` - i.e. it needs to be in a package itself (either "comment" or "mypackage123"). Also post the output of `go env`. – elithrar Feb 22 '14 at 14:10
  • @elithrar, although I agree that `main.go` shouldn't be located on `src/main.go`, it doesn't explain the compile failure. – Nico Feb 22 '14 at 15:41
  • Did you export $GOPATH? If you don't export it, go won't pick it up. – fuz Feb 22 '14 at 23:38

1 Answers1

0

I feel like your directory structure is wrong:

go/src/comment/create

should be something like

go/src/github.com/"your git org"/comment/create

For instance, my github organization is SupportLocal, my repo is "Comment", create is my go package name, my directory would look like this:

go/src/github.com/supportlocal/comment/create

Then your import would look like this:

"github.com/supportlocal/comment/create"

Let me know if that works.

Cory LaNou
  • 861
  • 5
  • 10