@@ -484,6 +484,45 @@ Example:
484
484
module golang.org/x/net
485
485
```
486
486
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
+
487
526
### ` go ` directive {#go-mod-file-go}
488
527
489
528
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
1254
1293
line arguments or to satisfy upgrades and downgrades), ` go get ` will report an
1255
1294
error.
1256
1295
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.
1262
1303
1263
1304
After ` go get ` updates the ` go.mod ` file, it builds the packages named
1264
1305
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:
1386
1427
1387
1428
```
1388
1429
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
1401
1443
}
1402
1444
1403
1445
type ModuleError struct {
@@ -1425,14 +1467,16 @@ is set to `Replace.Dir`, with no access to the replaced source code.)
1425
1467
1426
1468
The ` -u ` flag adds information about available upgrades. When the latest version
1427
1469
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:
1433
1476
1434
1477
```
1435
1478
example.com/main/module
1479
+ golang.org/x/old v1.9.9 (deprecated)
1436
1480
golang.org/x/net v0.1.0 (retracted) [v0.2.0]
1437
1481
golang.org/x/text v0.3.0 [v0.4.0] => /tmp/text
1438
1482
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.
1447
1491
Retracted versions are omitted from this list unless the ` -retracted ` flag
1448
1492
is also specified.
1449
1493
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
1452
1496
resolving [ version queries] ( #version-queries ) . For example, `go list -m
1453
1497
-retracted example.com/m@latest` shows the highest release or pre-release
1454
1498
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.
1457
1502
1458
1503
The template function ` module ` takes a single string argument that must be a
1459
1504
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.
3741
3786
<a id =" glos-current-module " ></a >
3742
3787
** current module:** Synonym for [ main module] ( #glos-main-module ) .
3743
3788
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
+
3744
3796
<a id =" glos-go-mod-file " ></a >
3745
3797
** ` go.mod ` file:** The file that defines a module's path, requirements, and
3746
3798
other metadata. Appears in the [ module's root
0 commit comments