Skip to content

cmd/go: reserve example/ and test/ as non-stdlib path prefixes #37641

Closed
@bcmills

Description

@bcmills

The go command automatically fetches modules from network hosts, provided that those modules have a path whose first element includes a dot character (.).

First-elements that do not include a dot are, in general, reserved for the standard library and the Go toolchain (see #32819). Some names (std, cmd, all) have a special meaning no matter where they are used. Others (such as archive and debug) are currently standard-library prefixes but not packages, but could be made so in the future (as was done in the case of encoding).

Still others currently have no meaning, but may be assigned a special meaning in the future: for example, I would like to add mod to refer to the main module independent of its path (that would be a separate proposal).

The fact that import paths are required to contain a dot occasionally causes user consternation (#37554, #34592).

I propose that we explicitly reserve the following package paths for user code:

  • for general use:
    • local
      • But not localhost, which we may at some point want to treat as a hostname.
  • for documentation, tutorials, and bug reports:
    • example (along the lines of example.com, because it looks more like “something you should replace” than local does)
  • for tests, especially tests of tools that manipulate modules (and thus need a “clean” module to run in):
  • for module-graph and package-import-graph examples:
    • main (because it is useful to indicate "the main module", and a package main is not importable anyway), and
    • any valid module path that consists of a single letter, because we already use those a lot in cmd/go tests.

CC @bronze1man @DisposaBoy @mvdan @jayconrod @matloob @thepudds

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions