Skip to content

proposal: cmd/go: extend syntax go.mod to allow overriding fetch protocol #39536

Open
@narqo

Description

@narqo

Update

The original proposal was build on the idea that we could extend replace directive (see the original text below).

After several rounds of discussions here in the comments, the current semantics of replace isn't about fetching the dependency but about local substitution of the source path and version (see this comment from @bcmills).

I have re-title the proposal and suggested the new syntax to solve the described problem.

Original Proposal

I propose to extend the syntax of go.mod's replace directive to support overwriting the protocol, which Go will use to fetch the module. That is

replace example.com/foo/bar => git+ssh://private.example.com/foo/bar

Background

As it’s for Go 1.14, the syntax of replace directive in go.mod allows overwriting module’s import path by defining an alternative version, alternative import path, or a path on the local FS (refer to [1]).

For non-FS-based replaces, Go fetches the replaced modules from modules proxy server as it does for other dependencies.

If a project uses private dependencies or private forks to replace a dependency, managing the modules become an extra burden for the developers, who work on the project. Even though the dependency is an attribute of the project itself, it’s the responsibility of every developer of the project to define the correct values for GOPRIVATE, GONOPROXY, etc, which alters their "normal" development workflow.

With private dependencies explicitly listed as the ones, that can't be fetched from any modules-proxy server, the project's workflow wouldn't be any different from a project, that only uses public modules (providing that a developer has the required accesses).

Specifying the protocol explicitly would also solve the issue where “go get” chooses to fetch a private dependency via HTTPS, which usually forces developers to manipulate their host’s .gitconfig, adding custom insteadOf rules to force go-get to use SSH when downloading modules from GitHub repositories.

Prior Experience

Dependency-management systems in other programming languages have similar mechanisms. For example:

  • Node.js + NPM
    package.json "dependency" syntax accepts URLs, Git URLs and some other [2].

  • Rust + Cargo
    Cargo.toml allows overwriting the source of the dependent crate, passing project’s Git URL [3].

  • Go + dep
    Gopkg.toml allows specifying dependencies' source as an alternate location, passing the URL [4].

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions