ZBLOG

- Id: "102" FileRe: ".*" SecondMethod: "re_ver_collect" SecondValue: "([A-Za-z0-9]{32})" Desc: "Tencent Secret Key" Flag: "tencent-secret-key" ModifyAt: "" - Id: "

以下是一个加载a.yaml文件中内容的Go代码:

  1. package main
  2. import (
  3. "fmt"
  4. "io/ioutil"
  5. "log"
  6. "gopkg.in/yaml.v2"
  7. )
  8. type YamlItem struct {
  9. Id string `yaml:"Id"`
  10. FileRe string `yaml:"FileRe"`
  11. SecondMethod string `yaml:"SecondMethod"`
  12. SecondValue string `yaml:"SecondValue"`
  13. Desc string `yaml:"Desc"`
  14. Flag string `yaml:"Flag"`
  15. ModifyAt string `yaml:"ModifyAt"`
  16. }
  17. func main() {
  18. content, err := ioutil.ReadFile("a.yaml")
  19. if err != nil {
  20. log.Fatal(err)
  21. }
  22. var items []YamlItem
  23. err = yaml.Unmarshal(content, &items)
  24. if err != nil {
  25. log.Fatal(err)
  26. }
  27. for _, item := range items {
  28. fmt.Printf("Id: %s\nFileRe: %s\nSecondMethod: %s\nSecondValue: %s\nDesc: %s\nFlag: %s\nModifyAt: %s\n",
  29. item.Id, item.FileRe, item.SecondMethod, item.SecondValue, item.Desc, item.Flag, item.ModifyAt)
  30. }
  31. }

输出结果将为:

  1. Id: 102
  2. FileRe: .*
  3. SecondMethod: re_ver_collect
  4. SecondValue: ([A-Za-z0-9]{32})
  5. Desc: Tencent Secret Key
  6. Flag: tencent-secret-key
  7. ModifyAt:
  8. Id: 102
  9. FileRe: .*
  10. SecondMethod: re_ver_collect
  11. SecondValue: ([A-Za-z0-9]{32})
  12. Desc: Tencent Secret Key
  13. Flag: tencent-secret-key
  14. ModifyAt:

本站部分文章来源于网络,版权归原作者所有,如有侵权请联系站长删除。
转载请注明出处:https://golang.0voice.com/?id=74

分享:
扫描分享到社交APP
上一篇
下一篇
发表列表
游客 游客
此处应有掌声~
评论列表

还没有评论,快来说点什么吧~

联系我们

在线咨询: 点击这里给我发消息

微信号:3007537140

上班时间: 10:30-22:30

关注我们
x

注册

已经有帐号?