'How do you mark code as deprecated in Go?

In Go, how do you mark code as deprecated so that users get a warning when using it?

go


Solution 1:[1]

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.

Solution 2:[2]

Add this Comment to your function / struct // Deprecated: FunctionName is deprecated.

Solution 3:[3]

There is no support for this in the Go compiler (neither in 5g/6g/8g nor in gccgo).

As far as I know, there is currently no code checking tool for this.

The only way is to put the deprecation warning in documentation, or simply delete the code.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 GoHumble
Solution 3