title: How to parse YAML with dynamic key in Golang
body: <p>I am trying to parse a YAML file with Go. The problem is that the keys in the YAML file might not always be the same. This is to do API versioning so the user can define the versions they support. For instance V1, V2, V3 etc. They do not need to be in order and can omit versions they don't support i.e,  V0, V2, V5 etc.</p>
  
  <pre><code>package main
  
  import (
    "fmt"
    "gopkg.in/yaml.v2"
  )
  
  var data = `
  ---
  development:
    skip-header-validation: true
    V1:
      current: "1.0.0"
      mime_types:
        - application/vnd.company.jk.identity+json;
        - application/vnd.company.jk.user+json;
        - application/vnd.company.jk.role+json;
        - application/vnd.company.jk.scope+json;
        - application/vnd.company.jk.test+json;
      skip-mime-type-validation: true
      skip-version-validation: true
    V2:
      current: "2.0.0"
      mime_types:
        - application/vnd.company.jk.identity+json;
        - application/vnd.company.jk.user+json;
        - application/vnd.company.jk.role+json;
        - application/vnd.company.jk.scope+json;
        - application/vnd.company.jk.test+json;
  
  `
  
  type MajorVersion struct {
    Current                 string    `yaml:"current"`
    MimeTypes               []string  `yaml:"mime_types"`
    SkipVersionValidation   bool      `yaml:"skip-version-validation"`
    SkipMimeTypeValidation  bool      `yaml:"skip-mime-type-validation"`
  }
  
  type Environment struct {
    SkipHeaderValidation  bool        `yaml:"skip-header-validation"`
    Version               map[string]MajorVersion
  }
  
  func main() {
    e := Environment{}
  
    yaml.Unmarshal([]byte(data), &amp;e)
    fmt.Println(e)
  }
  </code></pre>
  
  <p>I saw a <a href="https://stackoverflow.com/questions/18412126/golang-parse-a-json-with-dynamic-key">similar question asked here</a></p>
  
  <p>This is at the top level and I haven't quite figured out how to do this from inside the struct.</p>