I appreciate the inline if-else statements. I'm so tired of having:
if err != nil { return err }
Take up 70% of all lines in a function.
if err != nil { return err }
Take up 70% of all lines in a function.
err = doSomething
if err != nil {
return err
}
do: if err = doSomething(); err != nil {
return err
}
Also if your function only returns err, I'd use a named return to save even more typing. I know they are seen as a bit of a red-headed stepchild by much of the Go community these days, but I still like them if used carefully: func whatever() (err error) {
if err = doSomething(); err != nil {
return
}
...
}if buf, err := json.Marshal(make(chan int)); err != nil { fmt.Println("Ehh..", err) return }
In this case, buf will not be available outside of the if statement. Go fmt can already leave your insignificant whitespace as is, I just wish it could also leave the if error != nil statement say in one line instead of formatting it to take three.