I\'m new to go and finding the error handling to be extremely verbose. I\'ve read the reasoning for it and mostly agree, but there are a few places where it seems like ther
In a situation like this, I usually just flatten it out a bit.
func myFunc() (err error) {
cmd := exec.Command("cat", "-")
stdin, err := cmd.StdinPipe(); if err != nil { return }
stdout, err := cmd.StdoutPipe(); if err != nil { return }
err = cmd.Start(); if err != nil { return }
_, err = io.WriteString(stdin, "Hello world!"); if err != nil { return }
err = stdin.Close(); if err != nil { return }
o, err := ioutil.ReadAll(stdout); if err != nil { return }
fmt.Println(string(o))
return
}
Still ugly, but at least it's less vertical, and we get some alignment.
I can't say this adheres to any sort of convention, but it's a whole lot easier to read IMO.