分享Go命名规范小记

Դhttp://www.6cu.com

ߣ论坛外链

20

2021-04-06 09:24:00

下面由栏目给大家分享Go命名规范小记,希望对需要的朋友有所帮助!

  • 使用 camelCase
  • 首字母缩写应为全大写字母,如 ServeHTTP
  • 单个字母表示索引:i, j, k
  • 简短但具有描述性的名称:cust 而不是 customer
  • 重复字母以表示集合,切片或数组,并在循环中使用单个字母:
var tt []*Thingfor i, t := range tt {
  ...
}
  • 避免重复的包名:
log.Info()    // good
log.LogInfo() // bad
  • 不要像 getters 或 setters 这样命名:
custSvc.cust()    // good
custSvc.getCust() // bad
  • 将 er 添加到接口
type Stringer interfaces {
  String() string
}

更多golang技术文章,请访问栏目!

佭ϴý Ѷ Media8ý

在线客服

外链咨询

扫码加我微信

微信:xmbfjc

返回顶部