9

So I downloaded minio from github.com/minio/minio

I want to run it from the source,

I create my directory like:

~/Downloads/minio-RELEASE.2017-06-13T19-01-01Z
|
 src
   |
    all minio directories, including vendor, like the image below

enter image description here

I also use godep resolve other dependencies under GOPATH.

Now I run it from Gogland(go IDE)

It shows:

GOROOT=/usr/local/Cellar/go/1.8.3/libexec
GOPATH=/Users/xl/Downloads/minio-RELEASE.2017-06-13T19-01-01Z:/Users/xl/go
/usr/local/Cellar/go/1.8.3/libexec/bin/go build -i -o /private/var/folders/8v/6dg7d6mx2850sv1gp8ts9thm0000gn/T/go_run_main_gogo /Users/xl/Downloads/minio-RELEASE.2017-06-13T19-01-01Z/src/main.go
unexpected directory layout:
    import path: github.com/Azure/azure-sdk-for-go/storage
    root: /Users/xl/Downloads/minio-RELEASE.2017-06-13T19-01-01Z/src
    dir: /Users/xl/Downloads/minio-RELEASE.2017-06-13T19-01-01Z/src/vendor/github.com/Azure/azure-sdk-for-go/storage
    expand root: /Users/xl/Downloads/minio-RELEASE.2017-06-13T19-01-01Z/src
    expand dir: /Users/xl/Downloads/minio-RELEASE.2017-06-13T19-01-01Z/src/vendor/github.com/Azure/azure-sdk-for-go/storage
    separator: /

Now I am confused that, what's the problem? The files are all there and the directories are just like what's it's printing. How do I fix it? Thanks.

Wingzero
  • 9,644
  • 10
  • 39
  • 80

6 Answers6

26

On Golang 1.13 it suddenly happened to me on all my code after upgrading from 1.11 to 1.13.

It seems golang 1.13 does not like anymore imports like "./something".

I had to develop any import like "myapp/something"

  • Addendum: Now the best way is to use modules. create a module from your code with go mod init, then insert the reference to your directories as a 'replace' directive. See https://blog.golang.org/using-go-modules for more info – Philippe Thomassigny Jan 25 '21 at 17:50
8

See GitHub code layout

$GOPATH is the root of the project - each of your Github repos will be checked out several folders below $GOPATH.
Your $GOPATH variable will point to the root of your Go workspace, as described in How to Write Go Code.

In your case, below your GOPATH folder, you should have

src/github.com/minio/minio

Anf only then "all minio directories, including vendor"

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thank you for your reply. But I am new to go and still unclear how to fix it.. you said I should have `src/github.com/minio/minio`, but minio I have is the source code directly, not downloaded bo `go get` – Wingzero Aug 01 '17 at 06:40
  • 1
    @Wingzero create `GOPATH/src/github.com/minio`, then clone your repo inside that folder: that will give you `GOPATH/src/github.com/minio/minio`, and `go build` will work then. Or, simply try a `go get github.com/minio/minio`: that should do the same (clone + build) – VonC Aug 01 '17 at 06:42
  • Amazing, it's working. Thanks a lot! One pity is Gogland still fails to debug break at my breakpoint. Anyway – Wingzero Aug 02 '17 at 02:39
  • If you tell me where to set the breakpoints I'll follow up with an issue here https://youtrack.jetbrains.com/issues/Go and hopefully fix it. – dlsniper Aug 02 '17 at 08:15
6

This can happen if you have duplicate repos under goroot AND gopath. Delete the goroot one.

Sentinel
  • 3,582
  • 1
  • 30
  • 44
3

Also with go1.13 (with the move to go mod), I found if I moved my project out from under my $GOPATH, I could use the import "./mypackage" statement. The same project under $GOPATH wouldn't build with the errors given by the OP above. I'm not ready to give up my $GOPATH environment variable just yet but I do like to keep small packages local to their project when possible, without committing to a go.mod file when it's not necessary.

WeakPointer
  • 3,087
  • 27
  • 22
1

If your project folders are under $GOPATH directory, Then you should import your packages without using "./package".

You can import packages with "./package" name only if your project files are outside the $GOPATH

Ashok v
  • 77
  • 1
  • 8
0

I had this issue after I realised that I can't import correctly local packages, due to my project location. My project was not in the GOPATH location, so I moved my project there. Before moving

I imported packages via ./package name and after I moved my project in the GOPATH, I imported packages correctly via projectname/packagename.

So what I've done was to import packages the correct way "projectname/packagename", so I corrected my import "./packagename" to ""projectname/packagename. Hopefully it's not too confusing. It seems that this error can appear from different situations.

Kakjens91
  • 11
  • 2