title: How to map yaml keys to structs in golang?
body: <p>I'm looking to write a go script that can parse through a yaml file.  I created a test yaml file with the following:</p>
  
  <pre><code>    Dog:
        - name: "Dog"
        - secrets:
            username: "Shiba"
            password: "inu"
            color: "yellow"
      Cat:
        - name: "Cat"
        - secrets:
            words: "meow"
            color: "black"
  </code></pre>
  
  <p>What would the mapping to a struct look like in go?</p>
  
  <p>I've tried along the lines of:</p>
  
  <pre><code>            package main
  
              import (
                  "fmt"
                  "log"
  
                  "github.com/spf13/viper"
              )
  
              type Animal struct {
                  Animal  []string
                  Name    string
                  Secrets []map[string]string
              }
  
              func main() {
                  viper.SetConfigName("demo")
                  viper.AddConfigPath(".")
                  viper.SetConfigType("yaml")
  
                  err := viper.ReadInConfig()
  
                  if err != nil {
                      log.Fatal(err)
                  }
  
                  var animal Animal
                  err = viper.Unmarshal(&amp;animal)
                  if err != nil {
                      log.Fatal(err)
                  }
  
                  fmt.Println(animal.Name)
              }
  </code></pre>
  
  <p>But nothing is returned</p>
  
  <p>Any help would be much appreciated</p>
  
  <p>Thanks</p>