If you have a go-only repo (let's say it's https://github.com/foo/bar), you can put your code right at the root level, and have others import using the following command:
go get -u github.com/foo/bar
Directories and subdirectories therein would be recognized as packages.
But suppose you are creating a multi-language repo on github (e.g. one that has java code, go code, javascript code, etc.). And you want to make your go code available for others to use. Usually putting the go code right at the root level would be a no-no from the code organization standpoint. What might be more common may be
(root)
|-- src
|-- main
|-- go
|-- java
|-- javascript
|-- proto
The root level of your go code is now at https://github.com/foo/bar/src/main/go. But you can no longer use the previous go get
command as it would look at the top level. You don't really want to use go get -u github.com/foo/bar/src/main/go
either as all those would now become part of the package names which is real yucky.
Question is, is there a way to specify an exact URL so that you can separate the package names and the URL? In other words, I'm looking for something like
go get -u github.com/foo/bar https://github.com/foo/bar/src/main/go
(of course the package names should match those that are actually in the source, otherwise it won't compile).
I looked at the go documentation, but it isn't clear to me whether this is doable.
You've already answered the question yourself, so I'm just confirming that it is how you would do it.
In your example, you would use: go get -u github.com/foo/bar/src/main/go
Sure, it doesn't look pretty, but keep in mind that most of the yuckiness comes from paths in your control.
For example, it could be: go get -u github.com/foo/bar/go
I can confirm this works since this is what we use in production.
By design, the go get path is where you would get it from. You do have another option - to use redirection (like gopkg.in). However, that comes with its own added complexity.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With