1 回答
TA貢獻2016條經驗 獲得超9個贊
一個簡單的改變來完成你想要的事情是將數據yaml放在一個數組中的項目中,然后解組到一個切片中Container
var data = `
- first: first value
second:
nested1: GET
nested2: /bin/bash
nested3: /usr/local/bin/customscript
nested4: 8080
- first: second value
second:
nested1: POST
nested2: /bin/ksh
nested3: /usr/local/bin/customscript2
nested4: 8081
`
func main() {
container := []Container{}
err := yaml.Unmarshal([]byte(data), &container)
if err != nil {
log.Fatalf("error: %v", err)
}
fmt.Printf("---values found:\n%+v\n\n", container)
}
---values found:
[{First:first value Second:{Nested1:GET Nested2:/bin/bash Nested3:/usr/local/bin/customscript Nested4:8080}} {First:second value Second:{Nested1:POST Nested2:/bin/ksh Nested3:/usr/local/bin/customscript2 Nested4:8081}}]
- 1 回答
- 0 關注
- 435 瀏覽
添加回答
舉報
