title: Function that is returning struct or error
body: <p>I have method that looks like this:</p>
  
  <pre><code>var eventNotDetected = errors.New("Event not detected")
  
  type VoucherUsageEvent struct {
      M models.M
  }
  
  func detectVoucherUsageEvent(_ uint64, changeset changelog.Changeset) (VoucherUsageEvent, error) {
      var event VoucherUsageEvent
  
      if changeset.GetHeader().Table != db.TABLE_NAME {
          return event, eventNotDetected
      }
  
      switch changeset.(type) {
      case changelog.InsertChangeset, changelog.UpdateChangeset:
          m, err := models.Map(changeset)
  
          if err != nil {
              return event, err
          }
  
          return VoucherUsageEvent{m}, nil
  
      default:
          return event, eventNotDetected
      }
  }
  </code></pre>
  
  <p>The idea is that it can return an object instance or not, depending on the input. If the object instance can't be returned, the function should indicate why it could not be returned (error occurred during mapping, or just not found)</p>
  
  <p>The return signature is a bit weird when the function doesn't return the instance, for example:</p>
  
  <pre><code>return event, eventNotDetected
  return event, err
  </code></pre>
  
  <p>Basically I just use <code>event</code> because I can't return just nil. </p>
  
  <p>Or is the better way to just return a reference in this case, so I could change the return cases to:</p>
  
  <pre><code>return nil, eventNotDetected
  return nil, err
  </code></pre>