Yaml 输入:
Tasks:
- task:
name: 123
retry: 5
next: 123
- task:
name: 123
retry: 5
next: 123
代码:
package main
import (
"fmt"
"io/ioutil"
"os"
"gopkg.in/yaml.v2"
)
type Tasks []struct {
Task Task `yaml:"task"`
}
type Task struct {
Name string `yaml:"name"`
Retry int `yaml:"retry"`
Next string `yaml:"next"`
}
func main() {
var w Tasks
wfyaml, _ := os.Open(".yaml")
byteValue, _ := ioutil.ReadAll(wfyaml)
yaml.Unmarshal(byteValue, &w)
fmt.Printf("%+v\n", w)
}
输出:[]
我无法弄清楚问题的原因是什么。我已经检查了我能做的。
杨__羊羊
相关分类