yaml 编码

task:
 - { name: scchkj, path : /home/php/www/blogs }


安装库

go get gopkg.in/yaml.v2


声明 struct

type Task struct {
	Name string `yaml:"name"`
	Path string `yaml:"path"`
}

type Conf struct {
	Task []Task
}

注:这里需要你根据你的yaml 来声明你的struct 


https://zhwt.github.io/yaml-to-go/ (在线yaml 转 go struct 工具)


golang 获取 yaml 值

buf, _ := ioutil.ReadFile("./config.yaml")
    var conf Conf
    _ = yaml.Unmarshal(buf, &conf)
    for _, value := range conf.Task {
        // 这里开始输出
        value.Name
    }