I share some directories between machines with different user names. It would be useful to be able to add a statement like the following to a go.mod.
replace golang.org/x/net => ~/src/golang.org/x/net
Does the file support $HOME? Because ~ is some modern aberration (says the old grump).
It doesn't support $HOME either. I suggested ~ because $HOME would likely be the only expansion available, but I don't have a strong opinion between the two.
@FiloSottile I think adding this feature will be more complicated than we usually thought, I invite you to read https://unix.stackexchange.com/q/146671/38906
I also think it's a slippery slope to start putting expressions that must be evaluated into module specification.
@cuonglm, I think the natural meaning of ~/ in a Go-specific configuration file is os.UserHomeDir(), which is hopefully not ambiguous.
If you are going to do anything at all I think it should be to call os.ExpandEnv, but my vote would be to do nothing.
The idea of a checked in module line that varies its behavior depending on which machine it is checked out on sends chills down my spine.
I tend to agree with @ianthehat and @robpike on this. Relative paths are one thing, since there is a pretty solid use-case for pointing a replace directive into the same repository. And absolute paths are probably necessary for tool-driven edits (like CI scripts that inject replace directives). But I don't see a strong use-case for variable absolute paths.
See previously #27824.
I have a scenario for supporting ~ (expanding to user home directory):
Suppose there is a module/package named "A" on a desktop and on a notebook.
Because their username are different, "A" have two different paths:
On desktop: "A" is of path: "/home/pineapple/Dropbox/A"
On notebook: "A" is of path: "/home/orange/Dropbox/A"
On both the folder is symbolic linked to GOPATH "~/go/src/A"
So this configuration works in "package".
(For some reason that I can not change username or commit to github.com at this moment)
Now, if I want to "upgrade A" from package to module, I have to utility "replace" in go.mod to reference "A". The absolute path of "A" does not work for both. If the "replace" supports ~ or environ variables, it would be great!
Does it support the environment replacement (from https://github.com/golang/go/issues/27824) now? Like this:
go.mod
replace example.io/foo => $MYDIR/mod/foo
I happen to work with go.mod recently, and come into this need again. Unfortunately #27824 was closed due to the implementation complexity.
Most helpful comment
I also think it's a slippery slope to start putting expressions that must be evaluated into module specification.