美文网首页
go check 总结

go check 总结

作者: wolf4j | 来源:发表于2018-07-19 11:33 被阅读183次

一个优秀的工程,必然会对代码进行check,go本身提供了如下check工具,常用的有:

  • vet
  • golint
  • gofmt

现在简单记录一下这些格式可能会出的问题以及如何修改:

vet

composite literal uses unkeyed fields (vet)

这个是说明你调用了那个结构体,但是没有注明里面结构体的key值,例如:

type struct AAA{
      A int
      B int
}

当你调用AAA结构体填充内容时,需要在前面标明A,B。

struct field hash has json tag but is not exported (vet)

这个是说明,在结构体中的这个字段应该被导出,将字段名字的首字母改为大写即可。

the cancel function returned by context.WithCancel should be called, not discarded, to avoid a context leak (vet)

这个是说明,你的函数返回值不应该被忽略,这样可能会造成上下文忽略。

ctxChild, _ := context.WithCancel(ctx)

WithCancel有两个返回值context和func(需要被cacel的func),这个func参数是不可以省略的,会造成上下文的泄漏。

  1. unreachable code
if err != nil {
        log.Error("Error: ReadTxIndex======%#v", err)
        panic("Error: ReadTxIndex======")
        return nil, err
    }

上面的这段代码在panic之后,又return,因为panic之后,代码就已经结束了,下面的那句return语句永远不会执行。

相关文章

  • go check 总结

    一个优秀的工程,必然会对代码进行check,go本身提供了如下check工具,常用的有: vet golint g...

  • Free SSL certificate for HTTPS

    Go to Let's Encrypt and you're done. Go to here to check ...

  • cocoapods

    go to https://www.ipaddress.com/to check http://github-cl...

  • 英语03-这只猫真丑

    你知道石头剪刀布用英语怎么说嘛?rock paper scissors go! 原文对话 Ross: Check ...

  • go语言strings库总结

    最近由于用go做字符串处理,用到了go的strings库,借此对go strings库做个总结,将go strin...

  • golang第五天

    学习go操作mysql,crud测试 代码 总结 go操作mysql 打卡时间: 21:04

  • Golang基础(二)——流程控制语句

    Golang基础——流程控制语句 @([07] golang)[Go总结] [TOC] for循环语句 go只有f...

  • 学习总结

    +++TOP+++ go to bottom 学习总结文档 第一章 Copyright @ xxx go t...

  • 内存泄露

    内存泄露 实战 实战Go内存泄露 - Go语言实战 - SegmentFault 思否 总结 pprof工具 使用...

  • 文章目录

    Go 源码解读篇 《Go源码解读篇》之常见数据结构(list) 《Go源码解读篇》之 Error 工作中知识总结 ...

网友评论

      本文标题:go check 总结

      本文链接:https://www.haomeiwen.com/subject/xzazpftx.html