title: Golang yaml unmarshal structure
body: <p>I would need some help to handle configuration files in golang.<br />
  I renamed every fields and values for privacy (just saying)<br />
  I have this yaml configuration file :</p>
  <pre><code>Label1:
    field1: value1
    field2: value2
    field3: value3
    field4: value4
  Label2:
    field1: value1
    field2: value2
    field3: value3
    field4: value4
  Label3:
    field1: value1
    field2: value2
    field3: value3
    field4: value4
  </code></pre>
  <p>I'm using <a href="https://github.com/kylelemons/go-gypsy/tree/master/yaml" rel="nofollow noreferrer">https://github.com/kylelemons/go-gypsy/tree/master/yaml</a> to manually decode this yaml file into the structure below (manually walking the list of nodes). I don't have control over how many &quot;Label&quot; items will be on that file so I need a generic way of parsing it (and it is generic using the library mentioned above)</p>
  <pre><code>type Obj struct {
      Field1 string `yaml:&quot;field1&quot;`
      Field2 string `yaml:&quot;field2&quot;`
      Field3 string `yaml:&quot;field3&quot;`
      Field4 bool   `yaml:&quot;field4&quot;`
  }
  
  type ObjConfig struct {
      Objs map[string]Obj
  }
  </code></pre>
  <p>I have several other configuration files, much simpler, which I'm able to decode using annotations such as :</p>
  <pre><code>type conf1 struct {
      Field1 int    `yaml:&quot;field1&quot;`
      Field2 string `yaml:&quot;field2&quot;`
  }
  </code></pre>
  <p>I'm using the automatic yaml Unmarshal (through Viper framework) for these and it's working fine.</p>
  <p>It wasn't a big deal mixing these 2 ways of handling configuration files until now. But now I need to retrieve the file from a spring config server that I did set up instead of having the files locally. I'm using this library to do so :
  <a href="https://github.com/Piszmog/cloudconfigclient" rel="nofollow noreferrer">https://github.com/Piszmog/cloudconfigclient</a></p>
  <p>It's working well for structures annotated with the <code>yaml:&quot;fieldX&quot;</code>, I'm able to deserialize it directly.
  But for the first structure of course it's not working and I need a workaround. The library (cloudconfigclient) is using the classic yaml decoder so I can't write my own custom decoder. Looking at the library code it uses this code to deserialize the configuration file (with resp.Body being the yaml configuration file content) :</p>
  <pre><code>var dest interface{}
  yaml.NewDecoder(resp.Body).Decode(dest)
  </code></pre>
  <p>I'm able to change the configuraton file structure though, as long as I can get the same data in it. Maybe I could use something like</p>
  <pre><code>Labels:
    - Label1:
       field1: value1
       field2:value2
  ....
    - Label2:
       field1:value1
  ....
  </code></pre>
  <p>and use the yaml map handling from unmarshal ?</p>
  <p>I'm obviously not experienced with golang, I'd love to get some help here.</p>
  <p>To sum up, the question is how to decode the first yaml file using yaml.Unmarshal with the classic decoder (by either specific annotations that I don't know of, or changing the yaml structure itself).</p>