Christian Grabowski
Christian Grabowski

Reputation: 2892

Is it better to have golang statements go out to github or have relative path and why?

In golang import statements, is it better to have something like:

import(
    'project/package'
)

or

import(
    'github.com/owner/project/package'
)

for files local to your project?

For either option, why would you want to do one over the other?

I ask this because while it's easy and more intuitive to do the first one, I've also seen a lot of big projects like Kubernetes and Etcd do it the second way.

Upvotes: 1

Views: 103

Answers (1)

Mr_Pink
Mr_Pink

Reputation: 109416

These are exactly the same as far as the go build tools are concerned. The fact that package is in the directory

$GOPATH/src/github.com/owner/project/package

or in the directory

$GOPATH/src/project/package

makes no difference.

The only difference is that with the former you can use go get to fetch the source automatically, and the latter you have to clone the code yourself.

What you don't want to use are paths relative to the project itself, like

import "./project/package"

That is not compatible with all the go tools, and is highly discouraged.

Upvotes: 4

Related Questions