I'm looking to write a go script that can parse through a yaml file. I created a test yaml file with the following:
Dog:
- name: "Dog"
- secrets:
username: "Shiba"
password: "inu"
color: "yellow"
Cat:
- name: "Cat"
- secrets:
words: "meow"
color: "black"
What would the mapping to a struct look like in go?
I've tried along the lines of:
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(&animal)
if err != nil {
log.Fatal(err)
}
fmt.Println(animal.Name)
}
But nothing is returned
Any help would be much appreciated
Thanks