-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Description
Proposal Details
Abstract
This proposal introduces a deprecated {} block within the go.mod file of Go modules. Its goal is to provide a structured, automated, and backward-compatible way for module maintainers to communicate package deprecations, including details like the last usable version, the reason for deprecation, and an optional new import path for continued development.
Rationale
The current Go module system offers deprecation notices through comments (// Deprecated: ...) and the retract {} section in go.mod. However, these approaches have limitations in terms of visibility and automation. This proposal enhances this mechanism by introducing a dedicated, structured, and easily parseable method for declaring package deprecations.
Comparison with Current Mechanism
| Approach | Description | Pros | Cons |
|---|---|---|---|
Current (// Deprecated: ..., retract {}) |
Manual deprecation notices in comments or go.mod. |
Simple to implement. | Limited visibility and automation; lacks a standard format. |
Proposed (deprecated {}) |
Structured block in go.mod for deprecation details. |
Standardized, machine-readable format; enables automated handling of deprecated packages; detailed deprecation info and migration paths. | - |
Proposed Syntax Enhancements
The deprecated {} block in go.mod could allow both detailed and shorthand declarations:
Table of Fields
| Field | Required/Optional | Description |
|---|---|---|
version |
Required | The last usable version of the package or versions since package has been deprecated. |
message |
Optional | Explanation of why the package is deprecated. |
newpath |
Optional | New import path if package development has moved. |
Shorthand Declaration Example
module github.com/example/mypackage
go 1.23
require (
other/package v1.0.0
)
deprecated "v1.5.2" // Last usable versionDetailed Declaration Example
module github.com/example/mypackage
go 1.23
require (
other/package v1.0.0
)
deprecated {
version "v1.5.2"
message "Package deprecated due to XYZ reasons. Please migrate to the new version."
newpath "github.com/newowner/newpackage"
}Impact on Tooling
This feature can be integrated into tools like go get and go list, providing warnings or recommendations when using deprecated packages. IDE integrations could also leverage this feature to alert developers during coding.
Addressing Potential Concerns
- Backward Compatibility: The
deprecated {}block should be backward compatible, ignored by older Go versions. - Future Extensions: This feature could pave the way for more automated deprecation handling and better integration with dependency management tools.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status