What's the right way to handle this use case?
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/669b426e-5d0a-43a4-b086-e9e0c7213a9en%40googlegroups.com.
On Thu, Mar 4, 2021 at 12:02 AM Michael Ellis <michael...@gmail.com> wrote:What's the right way to handle this use case?I think the right way to handle it is to modify the file. In the final code, the import path should unambiguously point to where the code can be found - regardless of whether it was using your skeleton to get started. You might write a tool to do that modification automatically, if you want to simplify things.
Thanks even though it's not the answer I was hoping for. Seems to me that since the Go Authors have accorded special status to directories named "internal" the module mechanism should recognize references to it and not require a globally unique path string.
You should be able to use a `replace` directive to replace the full path "github.com/Michael-F-Ellis/skeleton/internal/common" or similar.
On Thu, Mar 4, 2021 at 12:55 AM Michael Ellis <michael...@gmail.com> wrote:Thanks even though it's not the answer I was hoping for. Seems to me that since the Go Authors have accorded special status to directories named "internal" the module mechanism should recognize references to it and not require a globally unique path string.
Maybe. There seem to be few downsides. Then again, your case is also fairly special.
On Thu, Mar 4, 2021 at 3:34 AM 'Bryan C. Mills' via golang-nuts <golan...@googlegroups.com> wrote:You should be able to use a `replace` directive to replace the full path "github.com/Michael-F-Ellis/skeleton/internal/common" or similar.Using replace would still mean that a module doesn't work, when used as a library. Generally, I feel that `replace` is being used for more and more things it wasn't designed for, leading to more and more friction and problems. I don't think we should encourage more off-label uses.
On Thursday, March 4, 2021 at 2:24:11 AM UTC-5 axel.wa...@googlemail.com wrote:On Thu, Mar 4, 2021 at 12:55 AM Michael Ellis <michael...@gmail.com> wrote:Thanks even though it's not the answer I was hoping for. Seems to me that since the Go Authors have accorded special status to directories named "internal" the module mechanism should recognize references to it and not require a globally unique path string.Maybe. There seem to be few downsides. Then again, your case is also fairly special.Not sure if my case is all that special. Seems like the requirement for a full path to an internal package breaks the concept of "internal" because it gives everyone import access to whatever the internal package exports. It would be good to have Russ and/or Ian weigh in on this. My feeling at this point is that either "internal" should be deprecated or the module mechanism needs to honor it.
On Thu, Mar 4, 2021 at 3:34 AM 'Bryan C. Mills' via golang-nuts <golan...@googlegroups.com> wrote:You should be able to use a `replace` directive to replace the full path "github.com/Michael-F-Ellis/skeleton/internal/common" or similar.Using replace would still mean that a module doesn't work, when used as a library. Generally, I feel that `replace` is being used for more and more things it wasn't designed for, leading to more and more friction and problems. I don't think we should encourage more off-label uses.Agree. Replace in this instance feels like a hack. Don't get me wrong, I like the concept behind go.mod and think it's generally a strong and useful design. That being said, I also agree with the sentiment expressed in a couple of other recent thread that the present implementation imposes a burden on coders who want to quickly sketch and test ideas in a local directory. It ought to be possible to progress at least a little way beyond Hello World before needing an external repo.
Not sure if my case is all that special. Seems like the requirement for a full path to an internal package breaks the concept of "internal" because it gives everyone import access to whatever the internal package exports.
It would be good to have Russ and/or Ian weigh in on this. My feeling at this point is that either "internal" should be deprecated or the module mechanism needs to honor it.On Thu, Mar 4, 2021 at 3:34 AM 'Bryan C. Mills' via golang-nuts <golan...@googlegroups.com> wrote:You should be able to use a `replace` directive to replace the full path "github.com/Michael-F-Ellis/skeleton/internal/common" or similar.Using replace would still mean that a module doesn't work, when used as a library. Generally, I feel that `replace` is being used for more and more things it wasn't designed for, leading to more and more friction and problems. I don't think we should encourage more off-label uses.Agree. Replace in this instance feels like a hack. Don't get me wrong, I like the concept behind go.mod and think it's generally a strong and useful design. That being said, I also agree with the sentiment expressed in a couple of other recent thread that the present implementation imposes a burden on coders who want to quickly sketch and test ideas in a local directory. It ought to be possible to progress at least a little way beyond Hello World before needing an external repo.
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/c7f87f45-b944-4f00-a6a6-ad3a8d1c5d4bn%40googlegroups.com.
On Thu, Mar 4, 2021 at 3:54 PM Michael Ellis <michael...@gmail.com> wrote:Not sure if my case is all that special. Seems like the requirement for a full path to an internal package breaks the concept of "internal" because it gives everyone import access to whatever the internal package exports.Really? I can't reproduce that. If I create a minimal module importing "github.com/Merovius/srvfb/internal/fb" and try to build that, I get an error message:foo.go:3:8: use of internal package github.com/Merovius/srvfb/internal/fb not allowedSo, the internal mechanism seems to work just fine, to me? Note that "every importer needs to mention the full path" is not the same as "everyone mentioning the full path can import".
My bad. I should have tested before writing that. Thanks for checking. Good to know the tools are enforcing the distinction. Still, the import path requirement does get in the way of being able to create a new application by cloning and revising an existing one without doing a recursive sed (or equivalent thereof).
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/35e46b0e-a730-4b27-9ca0-313ddfccf855n%40googlegroups.com.
I would argue that the “hack” in this case is the approach of defining the API in terms of copying in an entire tree of packages, rather than having users of the API make function calls into a specific set of (unmodified, un-relocated) packages with stable import paths.If the API is defined in terms or reflection over a set of types, why substitute a package rather than (say) having the caller pass in a set of instances of `reflect.Type` or similar?
On Thu, Mar 4, 2021 at 4:51 PM Michael Ellis <michael...@gmail.com> wrote:My bad. I should have tested before writing that. Thanks for checking. Good to know the tools are enforcing the distinction. Still, the import path requirement does get in the way of being able to create a new application by cloning and revising an existing one without doing a recursive sed (or equivalent thereof).I agree :) And as I said, we could probably make relative imports work. But currently, the mapping from import paths to packages in a single go binary is 1-1. If we would allow you to use relative imports as well, that would be lost. Or we would have to force you to do one or the other per module. Either way, it seems like a non-trivial and potentially confusing transition. At which point we get back to "your usecase seems fairly special". Not "using internal packages", but the entire "cloning an existing project/skeleton and expect to have that just work as the jumping-off point for a new one". Note that *some* search/replace like stuff is still going to be needed anyway - at the very least, `go.mod` needs to contain a user-chosen module path.That's why I really don't think it's worth changing. Overall, your use-case seems much better addressed by writing a tool that generates your skeleton, replacing paths as needed, instead of expecting `git clone` to serve that purpose.