title: Detecting uninitialized struct fields
body: <p>I have a service, written in golang, that can be initialized with some options. Options are passed as a struct to a constructor function. The constructor function uses default values for option fields that weren't included. Here's an example:</p>
  
  <pre><code>type Service struct {
    options Options
  }
  
  type Options struct {
    BoolOption bool
    StringOption string
  }
  
  const (
    DefaultBoolOption = true
    DefaultStringOption = "bar"
  )
  
  func New(opts Options) *Service {
    if !opts.BoolOption {
      opts.BoolOption = DefaultBoolOption
    }
  
    if len(opts.StringOption) &lt; 1 {
      opts.StringOption = DefaultStringOption
    }
  
    return &amp;Service{options: opts,}
  }
  
  ...
  
  // elsewhere in my code
  o := Options{BoolOption: false,}
  
  // sets s.options.BoolOption to true!!!
  s := New(o)
  </code></pre>
  
  <p>My problem is that for <code>bool</code> or <code>int</code> option types, I can't tell whether or not a field value was set in the Options struct. For example, was <code>BoolOption</code> set to false or just not initialized?</p>
  
  <p>One possible solution would be to use strings for all of my Options fields. For instance, <code>BoolOption</code> would be <code>"false"</code> rather than <code>false</code>. I could then check the length of the string to check if it was initialized.</p>
  
  <p>Are there better solutions?</p>