title: What is the idiomatic way to return either a struct or an error?
body: <p>I have a function that returns either a <code>Card</code>, which is a <code>struct</code> type, or an error.</p>
  
  <p>The problem is, how can I return from the function when an error occurs ? <code>nil</code> is not valid for structs and I don't have a valid zero value for my <code>Card</code> type.</p>
  
  <pre><code>func canFail() (card Card, err error) {
      // return nil, errors.New("Not yet implemented"); // Fails
      return Card{Ace, Spades}, errors.New("not yet implemented"); // Works, but very ugly
  }
  </code></pre>
  
  <p>The only workaround I found is to use a <code>*Card</code> rather than a <code>Card</code>, a make it either <code>nil</code> when there is an error or make it point an actual <code>Card</code> when no error happens, but that's quite clumsy.</p>
  
  <pre><code>func canFail() (card *Card, err error) {
      return nil, errors.New("not yet implemented");
  }
  </code></pre>
  
  <p>Is there a better way ?</p>
  
  <p>EDIT : I found another way, but don't know if this is idiomatic or even good style.</p>
  
  <pre><code>func canFail() (card Card, err error) {
      return card, errors.New("not yet implemented")
  }
  </code></pre>
  
  <p>Since <code>card</code> is a named return value, I can use it without initializing it. It is zeroed in its own way, I don't really care since the calling function is not supposed to use this value.</p>