gopkg.in/yaml.v2
文件 config.yaml 和程序入口文件在同一个目录
1 2 3 4 5 6
| TodoLists: - 测试1 - 测试2 - 测试3
CloudKey: adasdx7817238123213
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| package main
import ( "fmt" "io/ioutil" "gopkg.in/yaml.v2" )
type TodoLists struct { Lists []string `yaml:"TodoLists"` CloudKey string `yaml:"CloudKey"` }
func main(){ todolists:=TodoLists{} filePath:="./config.yaml" buffer,err := ioutil.ReadFile(filePath)
if err!=nil{ panic(err) } yaml.Unmarshal(buffer,&todolists)
for _,value := range todolists.Lists{ fmt.Println(value) }
}
|