title: Go method chaining and error handling
body: <p>I want to create a method chaining API in Go. In all examples I can find the chained operations seem always to succeed which I can't guarantee. I therefore try to extend these to add the error return value.</p>
  
  <p>If I do it like this</p>
  
  <pre><code>package main
  
  import "fmt"
  
  type Chain struct {
  }
  
  func (v *Chain)funA() (*Chain, error ) {
      fmt.Println("A")
      return v, nil
  }
  func (v *Chain)funB() (*Chain, error) {
      fmt.Println("B")
      return v, nil
  }
  func (v *Chain)funC() (*Chain, error) {
      fmt.Println("C")
      return v, nil
  }
  
  func main() {
      fmt.Println("Hello, playground")
      c := Chain{}
      d, err := c.funA().funB().funC() // line 24
  }
  </code></pre>
  
  <p>The compiler tells me <code>chain-err-test.go:24: multiple-value c.funA() in single-value context</code> and won't compile. Is there a good way so funcA, funcB and funcC can report an error and stop that chain?</p>