Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you mark code as deprecated in Go?

Tags:

go

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

like image 927
Mat Ryer Avatar asked Oct 21 '11 12:10

Mat Ryer


People also ask

What is a deprecated code?

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.

What does deprecated document mean?

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.

What happens when something is deprecated?

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.


2 Answers

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.

like image 131
Bayta Darell Avatar answered Nov 07 '22 20:11

Bayta Darell


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

like image 25
GoHumble Avatar answered Nov 07 '22 19:11

GoHumble