In Go, how do you mark code as deprecated so that users get a warning when using it?
Deprecation, in its programming sense, is the process of taking older code and marking it as no longer being useful within the codebase, usually because it has been superseded by newer code. The deprecated code is not immediately removed from the codebase because doing so may cause regression errors.
In information technology (IT), deprecation means that although something is available or allowed, it is not recommended or that -- in the case where something must be used -- to say it is deprecated means that its failings are recognized.
It means that it is bad practice to use it. It can still be used, but eventually it will not work with other things because it is no longer being supported.
Godoc: documenting Go code says this about marking code as deprecated:
To signal that an identifier should not be used, add a paragraph to its doc comment that begins with "Deprecated:" followed by some information about the deprecation.
The documentation site pkg.go.dev hides the documentation for deprecated identifiers behind a click of a "show" button.
The staticcheck tool reports use of deprecated identifiers (see SA1019).
There is a golint issue for reporting use of deprecated identifiers.
Add this Comment to your function / struct // Deprecated: FunctionName is deprecated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With