title: Custom UnmarshalYAML, how to implement Unmarshaler interface on custom type
body: <p>I parse a .yaml file and need to unmarshal one of its properties in a custom manner.  I am using the <code>"gopkg.in/yaml.v2"</code> package.  </p>
  
  <p>The property in question is stored like this in my .yaml file:</p>
  
  <pre><code>endPointNumberSequences:
    AD1: [ 0, 10, 14, 1, 11, 2, 100, 101, 12 ]
  </code></pre>
  
  <p>So it is basically a <code>map[string][]uint16</code> kind of type.<br>
  But I need <code>map[string]EpnSeq</code> where <code>EpnSeq</code> is defined as:<br>
  <code>type EpnSeq map[uint16]uint16</code></p>
  
  <p>My struct:</p>
  
  <pre><code>type CitConfig struct {
      // lots of other properties
      // ...
  
      EndPointNumberSequences  map[string]EpnSeq `yaml:"endPointNumberSequences"`
  }
  </code></pre>
  
  <p>I tried to implement the Unmarshaler interface on it like this:</p>
  
  <pre><code>// Implements the Unmarshaler interface of the yaml pkg.
  func (e EpnSeq) UnmarshalYAML(unmarshal func(interface{}) error) error {
      yamlEpnSequence := make([]uint16, 0)
      err := unmarshal(&amp;yamlEpnSequence)
      if err != nil {
          return err
      }
  
      for priority, epn := range yamlEpnSequence {
          e[epn] = uint16(priority) // crashes with nil pointer
      }
  
      return nil
  }
  </code></pre>
  
  <p>My problem is that inside the <code>UnmarshalYAML</code> function the <code>EpnSeq</code> type is not defined, causing a nil pointer exception at runtime.<br>
  How do I correctly implement the Unmarshaler interface here?</p>