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代码:

package main

import (
	"fmt"
	"io/ioutil"
	"log"

	"gopkg.in/yaml.v2"
)

type YamlItem struct {
	Id           string `yaml:"Id"`
	FileRe       string `yaml:"FileRe"`
	SecondMethod string `yaml:"SecondMethod"`
	SecondValue  string `yaml:"SecondValue"`
	Desc         string `yaml:"Desc"`
	Flag         string `yaml:"Flag"`
	ModifyAt     string `yaml:"ModifyAt"`
}

func main() {
	content, err := ioutil.ReadFile("a.yaml")
	if err != nil {
		log.Fatal(err)
	}

	var items []YamlItem
	err = yaml.Unmarshal(content, &items)
	if err != nil {
		log.Fatal(err)
	}

	for _, item := range items {
		fmt.Printf("Id: %s\nFileRe: %s\nSecondMethod: %s\nSecondValue: %s\nDesc: %s\nFlag: %s\nModifyAt: %s\n",
			item.Id, item.FileRe, item.SecondMethod, item.SecondValue, item.Desc, item.Flag, item.ModifyAt)
	}
}

输出结果将为:

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

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

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

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

联系我们

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

微信号:3007537140

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

关注我们
x

注册

已经有帐号?