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 there's more code to handle errors than actually do the work. Here is a (contrived) example, where I pipe "Hello world!" into cat and read and print the output. Basically every line has three more to handle the error, and I'm not really even handling anything.
package main
import "fmt"
import "io"
import "io/ioutil"
import "os/exec"
func main() {
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
}
output, err := ioutil.ReadAll(stdout)
if err != nil {
return
}
fmt.Println(string(output))
return
}
Is there an idiomatic, clean way to handle this? I just feel like I'm missing something.