go语言写个yml转换demo
时间: 2023-03-14 19:37:33 浏览: 121
Go语言demo
3星 · 编辑精心推荐
我可以为您提供一个用Go语言编写的YAML转换demo的简单示例:package mainimport (
"fmt"
"gopkg.in/yaml.v2"
)var data = `
a: Easy!
b:
c: 2
d: [3, 4]
`// Note: struct fields must be public in order for unmarshal to
// correctly populate the data.
type T struct {
A string
B struct {
C int
D []int
}
}func main() {
t := T{} err := yaml.Unmarshal([]byte(data), &t)
if err != nil {
panic(err)
} fmt.Printf("--- t:\n%v\n\n", t)
}
阅读全文