GoLand 提示 Receiver has generic name
GoLand Go About 1,041 words错误信息
The name of a method's receiver should be a reflection of its identity; often a one or two letter abbreviation of its type suffices (such as "c" or "cl" for "Client"). Don't use generic names such as "me", "this" or "self", identifiers typical of object-oriented languages that gives the method a special meaning. In Go, the receiver of a method is just another parameter and therefore, should be named accordingly. The name need not be as descriptive as that of a method argument, as its role is obvious and serves no documentary purpose. It can be very short as it will appear on almost every line of every method of the type; familiarity admits brevity. Be consistent, too: if you call the receiver "c" in one method, don't call it "cl" in another.
原因
Go
推荐的代码格式是尽量简洁的命名结构体的方法参数,不要使用面向对象中的this
、self
等词语。
解决
方法一(推荐)
将结构体的方法重命名为结构体的缩写。如Client
结构体,可以命名为c
或cl
。
方法二
关闭GoLand
提示。
Settings
- Editor
- Inspections
- Go
- Code Style issues
- Receiver has generic name
取消勾选。
参考
https://github.com/golang/go/wiki/CodeReviewComments#receiver-names
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb/LiteNote扫描下方二维码关注公众号和小程序↓↓↓