我正在寻找未结婚的简单yaml,但有些事情不对劲。已经花了足够的时间。请帮忙吗?
package main
import (
"fmt"
yaml "gopkg.in/yaml.v2"
)
func main() {
raw := `
targets:
- from: "http://localhost:8080/test1"
timeout: "10s"
- from: "http://localhost:8080/test2"
timeout: "30s"
`
type Target struct {
from string `yaml:"from"`
timeout string `yaml:"timeout"`
}
type config struct {
Targets []Target `yaml:"targets"`
}
cfg := config{}
err := yaml.Unmarshal([]byte(raw), &cfg)
if err != nil {
fmt.Println(err)
}
fmt.Println("Config", cfg)
}
我低于空的 o/p
Config {[{ } { }]}
儿童游乐场 -> https://play.golang.org/p/LANMpq_zPP9
森栏
相关分类