Skip to content

Commit f4600d6

Browse files
committed
content/static/doc: add introduction, resolve several TODOs
* Added Introduction. This should say generally what modules are. It should also say this is a reference document, and point to tutorials for folks looking for those. * Edited some text in introductory sessions. * Replaced emphasis on new terms with <dfn> tags. Dropped emphasis from terms that are being mentioned, not defined. * Added glossary term for "vendor directory". * Removed some TODOs that are no longer relevant. For golang/go#33637 Change-Id: Iae6dcd28b392a4cd94351bc645a059ead3a7dfa8 Reviewed-on: https://go-review.googlesource.com/c/website/+/247758 Reviewed-by: Bryan C. Mills <[email protected]> Reviewed-by: Michael Matloob <[email protected]>
1 parent 2bf8136 commit f4600d6

File tree

2 files changed

+53
-49
lines changed

2 files changed

+53
-49
lines changed

content/static/doc/mod.md

Lines changed: 52 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,46 @@
11
<!--{
22
"Title": "Go Modules Reference",
3-
"Subtitle": "Version of Feb 5, 2019",
3+
"Subtitle": "For Go 1.15",
44
"Path": "/ref/mod"
55
}-->
6-
<!-- TODO(jayconrod): use <dfn> tags where meaningful.
7-
Currently, *term* is used instead, which renders to <em>term</em>. -->
6+
<!-- TODO(golang.org/issue/33637): Write focused "guide" articles on specific
7+
module topics and tasks. Link to those instead of the blog, which will probably
8+
not be updated over time. -->
89

910
## Introduction {#introduction}
1011

12+
Modules are how Go manages dependencies.
13+
14+
This document is a detailed reference manual for Go's module system. For an
15+
introduction to creating Go projects, see [How to Write Go
16+
Code](https://golang.org/doc/code.html). For information on using modules,
17+
migrating projects to modules, and other topics, see the blog series starting
18+
with [Using Go Modules](https://blog.golang.org/using-go-modules).
19+
1120
## Modules, packages, and versions {#modules-overview}
1221

13-
A [*module*](#glos-module) is a collection of packages that are released,
14-
versioned, and distributed together. A module is identified by a [*module
15-
path*](#glos-module-path), which is declared in a [`go.mod`
16-
file](#go.mod-files), together with information about the module's
17-
dependencies. The [*module root directory*](#glos-module-root-directory) is the
18-
directory that contains the `go.mod` file. The [*main
19-
module*](#glos-main-module) is the module containing the directory where the
20-
`go` command is invoked.
21-
22-
Each [*package*](#glos-package) within a module is a collection of source files
23-
in the same directory that are compiled together. A [*package
24-
path*](#glos-package-path) is the module path joined with the subdirectory
25-
containing the package (relative to the module root). For example, the module
26-
`"golang.org/x/net"` contains a package in the directory `"html"`. That
27-
package's path is `"golang.org/x/net/html"`.
22+
A <dfn>module</dfn> is a collection of packages that are released, versioned,
23+
and distributed together. Modules may be downloaded directly from version
24+
control repositories or from module proxy servers.
25+
26+
A module is identified by a [module path](#glos-module-path), which is declared
27+
in a [`go.mod` file](#go.mod-files), together with information about the
28+
module's dependencies. The <dfn>module root directory</dfn> is the directory
29+
that contains the `go.mod` file. The <dfn>main module</dfn> is the module
30+
containing the directory where the `go` command is invoked.
31+
32+
Each <dfn>package</dfn> within a module is a collection of source files in the
33+
same directory that are compiled together. A <dfn>package path</dfn> is the
34+
module path joined with the subdirectory containing the package (relative to the
35+
module root). For example, the module `"golang.org/x/net"` contains a package in
36+
the directory `"html"`. That package's path is `"golang.org/x/net/html"`.
2837

2938
### Module paths {#module-path}
3039

31-
A [*module path*](#glos-module-path) is the canonical name for a module,
32-
declared with the [`module` directive](#go.mod-module) in the module's
33-
[`go.mod` file](#glos-go.mod-file). A module's path is the prefix for package
34-
paths within the module.
40+
A <dfn>module path</dfn> is the canonical name for a module, declared with the
41+
[`module` directive](#go.mod-module) in the module's [`go.mod`
42+
file](#glos-go.mod-file). A module's path is the prefix for package paths within
43+
the module.
3544

3645
A module path should describe both what the module does and where to find it.
3746
Typically, a module path consists of a repository root path, a directory within
@@ -55,7 +64,7 @@ version 2 or higher).
5564
`gopls`. See [Mapping versions to commits](#vcs-version) and [Module
5665
directories within a repository](#vcs-dir).
5766
* If the module is released at major version 2 or higher, the module path must
58-
end with a [*major version suffix*](#major-version-suffixes) like
67+
end with a [major version suffix](#major-version-suffixes) like
5968
`/v2`. This may or may not be part of the subdirectory name. For example, the
6069
module with path `golang.org/x/repo/sub/v2` could be in the `/sub` or
6170
`/sub/v2` subdirectory of the repository `golang.org/x/repo`.
@@ -67,8 +76,8 @@ module paths.
6776

6877
### Versions {#versions}
6978

70-
A [*version*](#glos-version) identifies an immutable snapshot of a module, which
71-
may be either a [release](#glos-release-version) or a
79+
A <dfn>version</dfn> identifies an immutable snapshot of a module, which may be
80+
either a [release](#glos-release-version) or a
7281
[pre-release](#glos-pre-release-version). Each version starts with the letter
7382
`v`, followed by a semantic version. See [Semantic Versioning
7483
2.0.0](https://semver.org/spec/v2.0.0.html) for details on how versions are
@@ -115,7 +124,7 @@ revisions that don't follow these conventions. However, within the main module,
115124
the `go` command will automatically convert revision names that don't follow
116125
this standard into canonical versions. The `go` command will also remove build
117126
metadata suffixes (except for `+incompatible`) as part of this process. This may
118-
result in a [*pseudo-version*](#glos-pseudo-version), a pre-release version that
127+
result in a [pseudo-version](#glos-pseudo-version), a pre-release version that
119128
encodes a revision identifier (such as a Git commit hash) and a timestamp from a
120129
version control system. For example, the command `go get -d
121130
golang.org/x/net@daa7c041` will convert the commit hash `daa7c041` into the
@@ -197,13 +206,13 @@ go list -m -json example.com/mod@abcd1234
197206

198207
### Major version suffixes {#major-version-suffixes}
199208

200-
Starting with major version 2, module paths must have a [*major version
201-
suffix*](#glos-major-version-suffix) like `/v2` that matches the major
202-
version. For example, if a module has the path `example.com/mod` at `v1.0.0`, it
203-
must have the path `example.com/mod/v2` at version `v2.0.0`.
209+
Starting with major version 2, module paths must have a <dfn>major version
210+
suffix</dfn> like `/v2` that matches the major version. For example, if a module
211+
has the path `example.com/mod` at `v1.0.0`, it must have the path
212+
`example.com/mod/v2` at version `v2.0.0`.
204213

205-
Major version suffixes implement the [*import compatibility
206-
rule*](https://research.swtch.com/vgo-import):
214+
Major version suffixes implement the [<dfn>import compatibility
215+
rule</dfn>](https://research.swtch.com/vgo-import):
207216

208217
> If an old package and a new package have the same import path,
209218
> the new package must be backwards compatible with the old package.
@@ -859,9 +868,6 @@ Note also that the `+incompatible` suffix may appear on
859868
[pseudo-versions](#glos-pseudo-version). For example,
860869
`v2.0.1-20200722182040-012345abcdef+incompatible` may be a valid pseudo-version.
861870

862-
<!-- TODO(jayconrod): Is it appropriate
863-
to link to the blog here? Ideally, we would have a more detailed guide. -->
864-
865871
### Minimal module compatibility {#minimal-module-compatibility}
866872

867873
A module released at major version 2 or higher is required to have a [major
@@ -902,8 +908,8 @@ directory in `GOPATH` mode:
902908
* `$vn` is a major version suffix,
903909
* `$dir` is a possibly empty subdirectory,
904910
* If all of the following are true:
905-
* The package `$modpath/$vn/$dir` is not present in any relevant `vendor`
906-
directory.
911+
* The package `$modpath/$vn/$dir` is not present in any relevant [`vendor`
912+
directory](#glos-vendor-directory).
907913
* A `go.mod` file is present in the same directory as the importing file
908914
or in any parent directory up to the `$GOPATH/src` root,
909915
* No `$GOPATH[i]/src/$modpath/$vn/$suffix` directory exists (for any root
@@ -923,8 +929,8 @@ Most `go` commands may run in *Module-aware mode* or *`GOPATH` mode*. In
923929
module-aware mode, the `go` command uses `go.mod` files to find versioned
924930
dependencies, and it typically loads packages out of the [module
925931
cache](#glos-module-cache), downloading modules if they are missing. In `GOPATH`
926-
mode, the `go` command ignores modules; it looks in `vendor` directories and in
927-
`GOPATH` to find dependencies.
932+
mode, the `go` command ignores modules; it looks in [`vendor`
933+
directories](#glos-vendor-directory) and in `GOPATH` to find dependencies.
928934

929935
Module-aware mode is active by default whenever a `go.mod` file is found in the
930936
current directory or in any parent directory. For more fine-grained control, the
@@ -951,7 +957,7 @@ build, but it still stores downloaded dependencies (in `GOPATH/pkg/mod`; see
951957

952958
When using modules, the `go` command typically satisfies dependencies by
953959
downloading modules from their sources into the module cache, then loading
954-
packages from those downloaded copies. *Vendoring* may be used to allow
960+
packages from those downloaded copies. <dfn>Vendoring</dfn> may be used to allow
955961
interoperation with older versions of Go, or to ensure that all files used for a
956962
build are stored in a single file tree.
957963

@@ -1817,13 +1823,6 @@ uppercase letter with an exclamation mark followed by the corresponding
18171823
lower-case letter. This allows modules `example.com/M` and `example.com/m` to
18181824
both be stored on disk, since the former is encoded as `example.com/!m`.
18191825

1820-
<!-- TODO(jayconrod): This table has multi-line cells, and GitHub Flavored
1821-
Markdown doesn't have syntax for that, so we use raw HTML. Gitiles doesn't
1822-
include this table in the rendered HTML. Once x/website has a Markdown renderer,
1823-
ensure this table is readable. If the cells are too large, and it's difficult
1824-
to scan, use paragraphs or sections below.
1825-
-->
1826-
18271826
<table class="ModTable">
18281827
<thead>
18291828
<tr>
@@ -2891,7 +2890,7 @@ of all environment variables recognized by the `go` command.
28912890
</li>
28922891
</ul>
28932892
<p>
2894-
See <a href="mod-commands">Module-aware commands</a> for more
2893+
See <a href="#mod-commands">Module-aware commands</a> for more
28952894
information.
28962895
</p>
28972896
</td>
@@ -3232,6 +3231,11 @@ paths](#module-path).
32323231
[version](#glos-version) to a specific revision. See [Mapping versions to
32333232
commits](#vcs-version).
32343233

3234+
<a id="glos-vendor-directory"></a>
3235+
**vendor directory:** A directory named `vendor` that contains packages from
3236+
other modules needed to build packages in the main module. Maintained with
3237+
[`go mod vendor`](#go-mod-vendor). See [Vendoring](#vendoring).
3238+
32353239
<a id="glos-version"></a>
32363240
**version:** An identifier for an immutable snapshot of a module, written as the
32373241
letter `v` followed by a semantic version. See the section on

0 commit comments

Comments
 (0)