We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
// BAD c := make(chan int, 100) // GOOD c := make(chan int)
// BAD if _, err := openFile("/path") { // do something } // GOOD var err error if _, err = openFile("/path") { // do something }
// GOOD var ( ok bool ) if _, ok = <- ch; !ok { // do something when channel is closed. }
The text was updated successfully, but these errors were encountered:
// go 会返回元素对应数据类型的零值,取值操作总有值返回,不能通过取出来的值来判断 key 是不是在 map 中
// error x := map[string]string{"demo1": "1", "demo2": "2"} if v := x["demo3"]; v == "" { fmt.Println("demo3 is not exist") } // right x := map[string]string{"demo1": "1", "demo2": "2"} if _, ok := x["demo3"]; !ok { fmt.Println("demo3 is not exist") }
Sorry, something went wrong.
// 防止为空的时候 panic
var ( a interface{} b int ok bool ) // BAD b = a.(int) // GOOD b, ok = a.(int)
// 定义常量, 区分某些类型、标识等
// BAD const ( Red = 0 Gray = 1 ) // GOOD const ( Red = iota Gray )
No branches or pull requests
监控团队Golang实践
理由:因为如果改为其他长度的channel,都需要很详细的评估设计,所以建议默认考虑长度为1或阻塞的channel
理由:如果再代码块中使用了新建变量,容易导致覆盖上层的变量而不会发现,容易引发bug
理由:可以避免读取已关闭channel导致panic
The text was updated successfully, but these errors were encountered: