go - 如何在 Go 中将代码标记为已弃用?

标签 go

在 Go 中,如何将代码标记为已弃用,以便用户在使用时收到警告?

最佳答案

Godoc: documenting Go code这是关于将代码标记为已弃用的:

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):

// 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 {  
    ⋮
}
                               

文档站点 pkg.go.dev在单击“显示”按钮后隐藏已弃用标识符的文档。

staticcheck工具报告使用了已弃用的标识符(请参阅 SA1019)。

Goland IDE code inspector报告使用了已弃用的标识符。

关于go - 如何在 Go 中将代码标记为已弃用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7849663/

相关文章:

docker - 如果有多个微服务,我应该如何集成测试它们?

go - 如何托管后端服务器?

go - 使用 new 初始化嵌套结构

unit-testing - 如何模拟getClient?

go - golang中如何判断unmarshal json interface{} type?

arrays - 函数应返回 sha256/sha384/sha512 结果作为 byte slice

go - 如何从 GO 结构中获取嵌入式类型?

go - 如何创建用 golang sciter 库编写的程序的 snap YAML 文件?

json - 如何创建包含 []byte 类型的嵌套 json 结构?

arrays - Helm : error converting YAML to JSON: yaml: line xx: did not find expected key