title: Working with interfaces using Viper language
body: <p>I am building a little app using <a href="https://github.com/spf13/viper" rel="noreferrer">Viper</a> and <a href="https://github.com/spf13/cobra" rel="noreferrer">Cobra</a>. At the moment, I have a yaml file like this:</p>
  
  <pre><code>hosts:
    - name: host1
      port: 90
      key: my_key
    - name: host2
      port: 90
      key: prompt
  </code></pre>
  
  <p>And I've read in the config file using Viper.</p>
  
  <p>When I run <code>viper.Get("hosts")</code> it returns an interface (or a slice of interfaces?). This is the data structure I end up with:</p>
  
  <pre><code>([]interface {}) (len=2 cap=2) {
   (map[interface {}]interface {}) (len=3) {
    (string) (len=4) "name": (string) (len=20) "host1",
    (string) (len=4) "port": (int) 90,
    (string) (len=3) "key": (string) (len=6) "my_key"
   },
   (map[interface {}]interface {}) (len=3) {
    (string) (len=3) "key": (string) (len=6) "prompt",
    (string) (len=4) "name": (string) (len=20) "host2",
    (string) (len=4) "port": (int) 90
   }
  }
  </code></pre>
  
  <p>What I'd like to do here is loop over each of the array elements and perform an operation using the values of name, port and key. </p>
  
  <p>I'm completely new to interfaces in Golang, so this isn't very clear, and the literature on this is extremely confusing :(</p>
  
  <p>Any help is appreciated.</p>