Documentation on how to reference a local copy of an internally developed package?

We have a package we want to maintain internally and re-use across projects. All the tutorials I can find on the subject seem to require use of a public 3rd-party git hosting website, which we don’t use for our projects.

So, presuming a developer has a copy of package A on their machine, can anyone point me in the direction of information on how to reference A in project B in an “import” directive?

We’ve tried placing the package in a “vendor” subdirectory but import "vendor/A" results in an error, “vendor/A must be imported as A”. Meanwhile import "A" results in an error “package A is not in GOROOT”. (Both of these are the result of a “go build” command.)

We tried following the example described at https://golang.org/doc/code#ImportingLocal and the result is the same.

Thanks in advance.

From my understanding you have a sole package sitting on a developers machine that they use? In my honest opinion I would possibly setup an internal Gitlab repository.

Alternatively, Go has provided the GOPRIVATE environmental variable, which can be used to direct to repositories that are not publicly available. So you can either upload the package to a private code repository, e.g., Github, or possibly direct it towards the users machine.

Are you using go modules? If yes, vendored modules have to be listed as “vendored” as far as I remember.

Also "A" is not a known member of the stdlib, so you can not use it for your own packages, in newer versions (since go 1.13 or 14) the first segment of a package name needs to have a . in it.

Last but not least, you do not need to use a public hosting service, you can also use self hosted GitLab. At my company we do it that way and it works well.

Gos dependency tracking deeply depends on everything beeing in git or other VCS.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.