-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/go: clarify go.mod documentation for trivial relative modules #27274
Comments
Setting aside for the moment the question of whether the documentation could be improved, here is a concrete example that might help. Sample file structure on my local system, all outside of GOPATH:
And the contents of /tmp/playground/hello/go.mod:
See a longer discussion and the rest of the example here (which is a runnable example if you are interested): |
@gopherbot please add label modules |
Thank you for the working module solution. Setting aside for the moment whether or not this is the canonical solution moving forward, it breaks when moving the code to the GOPATH, making the code non-backwards compatible. Is there another solution that works without changing the source code files? Otherwise it feels like a missing feature or a bug, instead of "a me not finding the right documentation" problem as I had assumed. Here is the original problem source updated to work with modules. ~/code/modtest/a: cat a.go package a func Hello() string { return "Hello" } ~/code/modtest/a: cat go.mod module example.com/me/a ~/code/modtest/a: go build ~/code/modtest/a: cd ../b ~/code/modtest/b: cat b.go package main import ( "fmt" "example.com/me/a" ) func main() { fmt.Printf("%s\n", a.Hello()) } ~/code/modtest/b: cat go.mod module example.com/me/b require example.com/me/a v0.0.0 replace example.com/me/a => ../a ~/code/modtest/b: go build ~/code/modtest/b: ./b Hello Moving both modules into the GOPATH results in the following:
|
If you return to the GOPATH world, then you would place the go source code back where Go 1.10 and earlier would expect it based on the import paths you are using in the code. E.g., something like If you don't like that And sorry if I am misunderstanding; this is all new... |
Thank you for your patience, adding just the
|
it's important to note, that you need the "require" AND the "replace" in the go.mod file. the go mod edit require example.com/post-adressdaten |
They are documented under That a I'm going to close this issue on the basis I think all questions have been answered, but please shout it not. |
@myitcv how about this case ?
how to call handler.Handler in cmd/main.go if code is not hosted on github but on cloud storage or private google cloud source repo ? I'd like to run cmd/main.go like this codelab for testing handler locally thanks ! |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?What did you do?
Created two modules
a
andb
in the same directory, not on theGOPATH
.Module
a
containsa.go, go.mod
:Module
b
containsb.go, go.mod
:What is the proper syntax for the line
require ../a v0.0.0
in this particular case?The closest I found in the docs (
go help modules, go help go.mod, go help mod
) was fromgo help importpath
:It is unclear to me if the second case is supposed to apply in this situation.
What did you expect to see?
I expect this to compile and run similarly to how it works with the existing GOPATH.
For example, copying the modules to the GOPATH gives the following:
What did you see instead?
The text was updated successfully, but these errors were encountered: