Skip to content

cmd/go: no easy way to use modules fully privately outside of GOPATH #37554

Closed
@marystern

Description

@marystern

What version of Go are you using (go version)?

$ go version
go version go1.14 linux/amd64

What did you do?

I'm trying out the new finalized modules feature in 1.14 and doing everything outside of GOPATH.
I want all my code to never be publicly visible (i.e. it's a fully private codebase and always will be).

I had an existing codebase with a main package and a separate "utility" package.
Under ~/go/src, everything works fine. But, to try out modules locally, I'm putting my code elsewhere (eg ~/src for the sake of example).

However, to migrate to using modules I'm now having to add a compulsory preceding domain to use the utility package from the main package, so eg, before I had this in my main program:

import "util/log"

which has to change to:

import "x.x/util/log"

"x.x" was the minimum domain name that I could think of that:
a) Would not accidentally resolve to a real domain
b) satisfies the "dot required" restriction in the tools.

My Issues:

  1. Inside the utility package itself, I cannot use relative imports, so I have a package util/email that uses util/log, and has now to be changed to import from x.x/util/log to allow "go test" to work (even though it's inside the same package!)
  2. I had set GOPRIVATE, but had changed the package name, so go was now trying to resolve and access domain x.x (I realize this is "user error", but is easy to get wrong accidentally, and leaks info very easily (there's another issue somewhere that mentions this).
  3. x.x is ugly, other ideas such as example.com, etc are all fine, but have the problem of looking like real places, and hence the leaking issue is a real security concern.
  4. Code is not portable from within GOPATH to outside (ie without adding doamin prefixes inside the codebase). (It's possible that this is "by design"?)
  5. The docs don't really help users to understand how to work in this very simple (fully local and private) case! My guess is that you would recommend using ~/go (and hence GOPATH), but I think I read somewhere that this is no longer the case?

Proposals

Two thoughts comes to mind (apologies for using this issue also for a prooposal):

  1. It might be fairly easy to just say "if the first part of an import does not have a dot in it, assume it's local and private and hence do none of the public module stuff at all". This has the advantage of being simple; not having to remember to set GOPRIVATE and keeping the code GOPATH-compatible.

  2. Another idea might be to use "_" as a fully private, local, never-publicly used domain name to indicate such usage in a Module World. So in this case, I could use

import "_/util/log"

Maybe there would be problems with these two ideas, but I'm throwing them out there, not as fully formed proposals, but rather to see if you can see the problem and come up with a good solution.

Anyway, I've been a golang user for many years, but Modules seem to be making my life 100 times harder for zero gain (in this particular case; of course I realize it's all brilliant for public code and dependency/version management, etc, so thanks, and keep up the good work :) )!

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.WaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.modules

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions