一、项目目录下执行:
  go vet ./...
 一般错误
  1.declared but not used
    变量定义没用
  2.unreachable code
    return/continue等代码已经返回了还有执行
  3.literal copies lock value from pool: sync.Pool contains sync.noCopy
    sync.Pool 发生了copy,一般就是代码new或者var发成了指针复制,,如下面
    ---------------------------修改前--------------------------------------------
    pool := sync.Pool{
       New: func() interface{} { return bufio.NewReaderSize(nil, size) },
    }
    return &BufferReaderPool{pool: pool}
    --------------------------修改后----------------------------------------------
    return &BufferReaderPool{pool: sync.Pool{
       New: func() interface{} { return bufio.NewReaderSize(nil, size) },
    }}
 二、代码风格
  go fmt ./...
  会自动格式化目录下所有代码文件
 三、静态检测
  go build -race

 

 

参考:https://mp.weixin.qq.com/s?__biz=MzkyMzIyNjIxMQ==&mid=2247484558&idx=1&sn=34b1f3112657c823cbc35e3e35ffee6b&source=41#wechat_redirect

相关文章:

  • 2021-05-04
  • 2021-09-12
  • 2021-09-17
  • 2021-11-03
  • 2021-12-30
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-15
  • 2021-12-12
  • 2022-02-14
  • 2021-10-20
  • 2021-12-25
相关资源
相似解决方案