title: Idiomatic way to represent optional time.Time in a struct
body: <p>I've read both <a href="https://stackoverflow.com/questions/2032149/optional-parameters">Optional Parameters?</a> and <a href="https://stackoverflow.com/questions/32568977/golang-pass-nil-as-optional-argument-to-a-function">Golang pass nil as optional argument to a function?</a></p>
  
  <p>And still wonder if my case is more specific.</p>
  
  <p>What I've got is:</p>
  
  <pre><code>type Periodical struct {
      Interval *interval.Interval
      StartsAt time.Time
      EndsAt   time.Time
  }
  </code></pre>
  
  <p>to represent periodical event which has a start date and <strong>may or may not</strong> have an end date (periodical event runs for indefinite amount of time).</p>
  
  <pre><code>eachYear := Periodical{
      interval.Years(1),
      StartsAt: time.Parse("2 Jan 2006", "1 Jan 1970")}
  </code></pre>
  
  <p>Will throw</p>
  
  <pre><code>periodical/periodical.go:31:39: cannot use nil as type time.Time in field value
  </code></pre>
  
  <p>Which is understood, - I didn't specify <code>EndsAt time.Time</code>.</p>
  
  <p>But what do I really do there then?</p>
  
  <p>Am I forced to have a special flag to neglect <code>EndsAt</code> like so?</p>
  
  <pre><code>type Periodical struct {
      Interval     *interval.Interval
      StartsAt     time.Time
      EndsAt       time.Time
      isIndefinite bool       // This looks ugly already
  }
  </code></pre>
  
  <p>and then if I want <code>Yearly</code> / <code>Anually</code> I do something like</p>
  
  <pre><code>eachYear := Periodical{
      interval.Years(1),
      time.Parse("2 Jan 2006", "1 Jan 1970"),
      time.Parse("2 Jan 2006", "1 Jan 1970"),
      isIndefinite: true}
  </code></pre>
  
  <p>Although, I can then account for this flag in business logic, but this <code>EndsAt</code> set to the same (or any other) date looks kind of dull.</p>
  
  <p>I also define a method on <code>periodical</code> package which allows to have a shorthand periodical event like so:</p>
  
  <pre><code>func Monthly(s, e time.Time) Periodical {
      return Periodical{StartsAt: s, EndsAt: e, Interval: interval.Months(1)}
  }
  </code></pre>
  
  <p>What do I do to omit <code>end</code> (the second param)? Am I forced to either have separate method for that or do something that looks a bit funky and lacks readability:</p>
  
  <pre><code>func Monthly(s time.Time, end ...time.Time) Periodical {
      if len(end) == 1  {
          return Periodical{
              StartsAt: s,
              EndsAt: end[0],
              Interval: interval.Months(1),
              isIndefinite: false}
      } else if len(end) &gt; 1 {
          panic("Multiple end dates are not allowed, don't know what to do with those")
      } else {
          return Periodical{
              StartsAt: s,
              EndsAt: time.Now(),
              Interval: interval.Months(1),
              isIndefinite: true}
      }
  }
  </code></pre>
  
  <p>Although it does the trick, it looks ugly, isn't it? My concise one-liner is now scattered along several lines of code.</p>
  
  <p>So, that's why I wonder, what's the go's idiomatic way of achieving what I'm trying to do?</p>