KGSQ3OPPOY27FODPPPNFANPK2QL462RVTQIX6DISNR2X5GIGEGUAC
package main
import (
"fmt"
"log"
yaml "gopkg.in/yaml.v2"
)
func main() {
input1 := `
- path: /foo
url: https://hup.hu
- path: /whatevs
url: http://index.hu
`
// Convert YAML to struct
type yamlStruct struct {
Path string
URL string
}
var test1 []yamlStruct
err := yaml.Unmarshal([]byte(input1), &test1)
if err != nil {
log.Printf("%s", err)
}
fmt.Println(test1)
input2 := `
entries:
- path: /foo
url: https://hup.hu
- path: /whatevs
url: http://index.hu
`
// Convert YAML to map[string]interface{}
// This will create separate map for each entry
type IntEntry map[string]interface{}
type mapStruct struct {
Element []IntEntry `yaml:"entries"`
}
var test2 mapStruct
err = yaml.Unmarshal([]byte(input2), &test2)
if err != nil {
log.Printf("%s", err)
}
fmt.Println(test2)
}