How do you mark code as deprecated in Go?
Add this Comment to your function / struct // Deprecated: FunctionName is deprecated.
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.
Here's an example of the syntax (view more here):
// Title treats s as UTF-8-encoded bytes and returns a copy with all Unicode letters that begin
// words mapped to their title case.
//
// Deprecated: The rule Title uses for word boundaries does not handle Unicode
// punctuation properly. Use golang.org/x/text/cases instead.
func Title(s []byte) []byte {
⋮
}
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).
The Goland IDE code inspector reports use of deprecated identifiers.