Skip to content

Commit fee037f

Browse files
author
Jay Conrod
committed
_content/doc: document module deprecation
For golang/go#40357 Change-Id: Iba0e912123287ed4fe5b0a34acca76b883046529 Reviewed-on: https://go-review.googlesource.com/c/website/+/309529 Trust: Jay Conrod <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent 0cf64a4 commit fee037f

File tree

1 file changed

+78
-26
lines changed

1 file changed

+78
-26
lines changed

_content/doc/mod.md

Lines changed: 78 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,45 @@ Example:
484484
module golang.org/x/net
485485
```
486486

487+
#### Deprecation {#go-mod-file-module-deprecation}
488+
489+
A module can be marked as deprecated in a block of comments containing the
490+
string `Deprecated:` (case-sensitive) at the beginning of a paragraph. The
491+
deprecation message starts after the colon and runs to the end of the paragraph.
492+
The comments may appear immediately before the `module` directive or afterward
493+
on the same line.
494+
495+
Example:
496+
497+
```
498+
// Deprecated: use example.com/mod/v2 instead.
499+
module example.com/mod
500+
```
501+
502+
Since Go 1.17, [`go list -m -u`](#go-list-m) checks for information on all
503+
deprecated modules in the [build list](#glos-build-list). [`go get`](#go-get)
504+
checks for deprecated modules needed to build packages named on the command
505+
line.
506+
507+
When the `go` command retrieves deprecation information for a module, it loads
508+
the `go.mod` file from the version matching the `@latest` [version
509+
query](#version-queries) without considering retractions or exclusions. The `go`
510+
command loads [retractions](#glos-retracted-version) from the same `go.mod`
511+
file.
512+
513+
To deprecate a module, an author may add a `// Deprecated:` comment and tag a
514+
new release. The author may change or remove the deprecation message in a higher
515+
release.
516+
517+
A deprecation applies to all minor versions of a module. Major versions higher
518+
than `v2` are considered separate modules for this purpose, since their [major
519+
version suffixes](#glos-major-version-suffix) give them distinct module paths.
520+
521+
Deprecation messages are intended to inform users that the module is no longer
522+
supported and to provide migration instructions, for example, to the latest
523+
major version. Individual minor and patch versions cannot be deprecated;
524+
[`retract`](#go-mod-file-retract) may be more appropriate for that.
525+
487526
### `go` directive {#go-mod-file-go}
488527

489528
A `go` directive indicates that a module was written assuming the semantics of a
@@ -1254,11 +1293,13 @@ If a module is needed at two different versions (specified explicitly in command
12541293
line arguments or to satisfy upgrades and downgrades), `go get` will report an
12551294
error.
12561295

1257-
After `go get` has selected a new set of versions, it checks whether any
1258-
newly selected module versions or any modules providing packages named on
1259-
the command line are [retracted](#glos-retracted-version). `go get` prints
1260-
a warning for each retracted version it finds. [`go list -m -u all`](#go-list-m)
1261-
may be used to check for retractions in all dependencies.
1296+
After `go get` has selected a new set of versions, it checks whether any newly
1297+
selected module versions or any modules providing packages named on the command
1298+
line are [retracted](#glos-retracted-version) or
1299+
[deprecated](#glos-deprecated-module). `go get` prints a warning for each
1300+
retracted version or deprecated module it finds. [`go list -m -u
1301+
all`](#go-list-m) may be used to check for retractions and deprecations in all
1302+
dependencies.
12621303

12631304
After `go get` updates the `go.mod` file, it builds the packages named
12641305
on the command line. Executables will be installed in the directory named by
@@ -1386,18 +1427,19 @@ to a Go struct, but now a `Module` struct:
13861427

13871428
```
13881429
type Module struct {
1389-
Path string // module path
1390-
Version string // module version
1391-
Versions []string // available module versions (with -versions)
1392-
Replace *Module // replaced by this module
1393-
Time *time.Time // time version was created
1394-
Update *Module // available update, if any (with -u)
1395-
Main bool // is this the main module?
1396-
Indirect bool // is this module only an indirect dependency of main module?
1397-
Dir string // directory holding files for this module, if any
1398-
GoMod string // path to go.mod file for this module, if any
1399-
GoVersion string // go version used in module
1400-
Error *ModuleError // error loading module
1430+
Path string // module path
1431+
Version string // module version
1432+
Versions []string // available module versions (with -versions)
1433+
Replace *Module // replaced by this module
1434+
Time *time.Time // time version was created
1435+
Update *Module // available update, if any (with -u)
1436+
Main bool // is this the main module?
1437+
Indirect bool // is this module only an indirect dependency of main module?
1438+
Dir string // directory holding files for this module, if any
1439+
GoMod string // path to go.mod file for this module, if any
1440+
GoVersion string // go version used in module
1441+
Deprecated string // deprecation message, if any (with -u)
1442+
Error *ModuleError // error loading module
14011443
}
14021444
14031445
type ModuleError struct {
@@ -1425,14 +1467,16 @@ is set to `Replace.Dir`, with no access to the replaced source code.)
14251467

14261468
The `-u` flag adds information about available upgrades. When the latest version
14271469
of a given module is newer than the current one, `list -u` sets the module's
1428-
`Update` field to information about the newer module. `list -u` will also print
1429-
whether the currently selected version is [retracted](#glos-retracted-version).
1430-
The module's `String` method indicates an available upgrade by formatting the
1431-
newer version in brackets after the current version. For example,
1432-
`go list -m -u all` might print:
1470+
`Update` field to information about the newer module. `list -u` also prints
1471+
whether the currently selected version is [retracted](#glos-retracted-version)
1472+
and whether the module is [deprecated](#go-mod-file-module-deprecation). The
1473+
module's `String` method indicates an available upgrade by formatting the newer
1474+
version in brackets after the current version. For example, `go list -m -u all`
1475+
might print:
14331476

14341477
```
14351478
example.com/main/module
1479+
golang.org/x/old v1.9.9 (deprecated)
14361480
golang.org/x/net v0.1.0 (retracted) [v0.2.0]
14371481
golang.org/x/text v0.3.0 [v0.4.0] => /tmp/text
14381482
rsc.io/pdf v0.1.1 [v0.1.2]
@@ -1447,13 +1491,14 @@ to display the module path followed by the space-separated version list.
14471491
Retracted versions are omitted from this list unless the `-retracted` flag
14481492
is also specified.
14491493

1450-
The `-retracted` flag instructs `list` to show retracted versions in the
1451-
list printed with the `-versions` flag and to consider retracted versions when
1494+
The `-retracted` flag instructs `list` to show retracted versions in the list
1495+
printed with the `-versions` flag and to consider retracted versions when
14521496
resolving [version queries](#version-queries). For example, `go list -m
14531497
-retracted example.com/m@latest` shows the highest release or pre-release
14541498
version of the module `example.com/m`, even if that version is retracted.
1455-
[`retract` directives](#go-mod-file-retract) are loaded from the `go.mod` file
1456-
at this version. The `-retracted` flag was added in Go 1.16.
1499+
[`retract` directives](#go-mod-file-retract) and
1500+
[deprecations](#go-mod-file-module-deprecation) are loaded from the `go.mod`
1501+
file at this version. The `-retracted` flag was added in Go 1.16.
14571502

14581503
The template function `module` takes a single string argument that must be a
14591504
module path or query and returns the specified module as a `Module` struct. If
@@ -3741,6 +3786,13 @@ is a canonical version, but `v1.2.3+meta` is not.
37413786
<a id="glos-current-module"></a>
37423787
**current module:** Synonym for [main module](#glos-main-module).
37433788

3789+
<a id="glos-deprecated-module"></a>
3790+
**deprecated module:** A module that is no longer supported by its authors
3791+
(though major versions are considered distinct modules for this purpose).
3792+
A deprecated module is marked with a [deprecation
3793+
comment](#go-mod-file-module-deprecation) in the latest version of its
3794+
[`go.mod` file](#glos-go-mod-file).
3795+
37443796
<a id="glos-go-mod-file"></a>
37453797
**`go.mod` file:** The file that defines a module's path, requirements, and
37463798
other metadata. Appears in the [module's root

0 commit comments

Comments
 (0)