Add yaml-unmarshal examples
[?]
Dec 27, 2020, 9:09 PM
KGSQ3OPPOY27FODPPPNFANPK2QL462RVTQIX6DISNR2X5GIGEGUACDependencies
Change contents
- file addition: yaml-unmarshal[4.11]
- file addition: main.go[0.17]
package mainimport ("fmt""log"yaml "gopkg.in/yaml.v2")func main() {input1 := `- path: /foourl: https://hup.hu- path: /whatevsurl: http://index.hu`// Convert YAML to structtype yamlStruct struct {Path stringURL string}var test1 []yamlStructerr := yaml.Unmarshal([]byte(input1), &test1)if err != nil {log.Printf("%s", err)}fmt.Println(test1)input2 := `entries:- path: /foourl: https://hup.hu- path: /whatevsurl: http://index.hu`// Convert YAML to map[string]interface{}// This will create separate map for each entrytype IntEntry map[string]interface{}type mapStruct struct {Element []IntEntry `yaml:"entries"`}var test2 mapStructerr = yaml.Unmarshal([]byte(input2), &test2)if err != nil {log.Printf("%s", err)}fmt.Println(test2)} - replacement in snippets/tictactoe/go.mod at line 5
require github.com/stretchr/testify v1.6.1[2.2004]require (github.com/stretchr/testify v1.6.1golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e // indirect)