当前位置: 首页 > news >正文

深圳最近几天的新闻大事seo关键词快速排名

深圳最近几天的新闻大事,seo关键词快速排名,建设网站修改图片,海淀网站建设公司本文对 yaml 文件进行解析。 下载 yaml执行 go get github.com/spf13/viper 安装。 golang 有很多库可以解释 yaml 文件。本文选用 viper 进行解析,执行 go get github.com/spf13/viper 安装。 yaml语法规则 yaml对大小写敏感。yaml的层级关系只能使用空格缩进&a…

本文对 yaml 文件进行解析。

下载

yaml执行 go get github.com/spf13/viper 安装。
golang 有很多库可以解释 yaml 文件。本文选用 viper 进行解析,执行 go get github.com/spf13/viper 安装。

yaml语法规则

  • yaml对大小写敏感。
  • yaml的层级关系只能使用空格缩进,同一层缩进的空格数量相同即可,数量不重要。不允许使用tab键。
  • 使用#进行注释,与shell一样。

测试

yaml 配置文件

# yaml测试样例
# null 或 NULL 为关键字,不能写# 表示 bool 真假的几个值
result_true: - y- Y- yes- Yes- YES- true- True- TRUE- on- On- ON# 数组的另一种形式
result_false: [n, N, no, No, NO , false, False, FALSE , off, Off, OFF]# 名称
# 字符串
name: conf file# 版本
# 如按浮点,2.0会转换成2
# 如按字符串,保留原样
version: 2.0# 布尔类,转换为1或0
need: true# 时间
time: 2020-10-03T09:21:13empty: nul# 对象
# 加双引号会转义\n,即会换行
my:name: late \n leename1: "late \n lee"age: 99# 块
text: |helloworld!# 数组
fruit:- apple- apple1- apple2- apple3- apple4- apple5# 多级数组
multi:sta:- 110 210 ddd 99- 133 135 1 2 1588 1509- 310-410- 333-444# 多层级
loginfo:log:dir: log# 多级对象
mymap:dir: "mymap"map_data:- name: "在线"attri: "在线电子"url: "http://abc.com"- name: "离线"attri: "离线电子"url: "http://ccc.com"# more

该示例基本涵盖了大部分的 yaml 格式。包括:字符串,数值、数组、多级map。

测试代码

测试代码如下:

package testimport ("fmt""os""testing""github.com/spf13/viper"
)var (cfgFile string
)type mapUrl_t struct {Name  string `json:"name"`Attri string `json:"attri"`Url   string `json:"url"`
}func TestYaml(t *testing.T) {fmt.Println("test of yaml...")// 设置配置文件的2种方式if cfgFile != "" {// Use config file from the flag.viper.SetConfigFile(cfgFile)} else {viper.AddConfigPath("./")viper.SetConfigName("config")viper.SetConfigType("yaml")}viper.AutomaticEnv() // read in environment variables that match// 读取err := viper.ReadInConfig()if err != nil {fmt.Println("'config.yaml' file read error:", err)os.Exit(0)}name := viper.GetString("name") // 读取 字符串version := viper.GetString("version")need := viper.GetBool("need") // 读取 布尔theTime := viper.GetString("time")empty := viper.GetString("empty")text := viper.GetString("text")fmt.Printf("need: %v name: %v\nversion: %v \ntime: %v \nempty: %s \ntext: %v\n", need, name, version, theTime, empty, text)// 多级读取name = viper.GetString("my.name")name1 := viper.GetString("my.name1")age := viper.GetInt("my.age")fmt.Printf("name: %v, name1: %v age: %v \n", name, name1, age)// 字符串数组newSta := viper.GetStringSlice("multi.sta")for idx, value := range newSta {fmt.Printf("sta[%d]: %v\n", idx, value)}fruit := viper.GetStringSlice("fruit")fmt.Printf("fruit: %v\n", fruit)// 读取不存在的字段,字符串为空,数值为0bad := viper.GetString("bad")bad1 := viper.GetInt("my.bad")fmt.Printf("bad: [%v] bad1: [%v]\n", bad, bad1)// 按数值、字符串读取on、off等值result := viper.GetIntSlice("result_true")fmt.Printf("result true: [%v]\n", result)result1 := viper.GetStringSlice("result_true")fmt.Printf("result1 true: [%v]\n", result1)result = viper.GetIntSlice("result_false")fmt.Printf("result false: [%v]\n", result)result1 = viper.GetStringSlice("result_false")fmt.Printf("result1 false: [%v]\n", result1)logdir := viper.GetString("loginfo.log.dir")fmt.Printf("logdir: %v\n", logdir)// 多级对象// tmpMap := make([]mapUrl_t, 0, 20)var tmpMap []mapUrl_tviper.UnmarshalKey("mymap.map_data", &tmpMap)for _, item := range tmpMap {fmt.Printf("name: %v url: %v\n", item.Name, item.Url)}
}

测试命令:

go test -v -run TestYaml

测试结果:

test of yaml...
need: true name: conf file
version: 2
time: 2020-10-03T09:21:13
empty: nul
text: hello
world!name: late \n lee, name1: latelee age: 99
sta[0]: 110 210 ddd 99
sta[1]: 133 135 1 2 1588 1509
sta[2]: 310-410
sta[3]: 333-444
fruit: [apple apple1 apple2 apple3 apple4 apple5]
bad: [] bad1: [0]
result true: [[1 1 1 1 1 1 1 1 1 1 1]]
result1 true: [[true true true true true true true true true true true]]
result false: [[0 0 0 0 0 0 0 0 0 0 0]]
result1 false: [[false false false false false false false false false false false]]
logdir: log
name: 在线 url: http://abc.com
name: 离线 url: http://ccc.com

结果说明

1、name: "late \n lee" 输出会换行。而 name: late \n lee 则会原样输出。
2、参数的值不能为 null 或 NULL,但可以为nul。如果为 null,解析的值为空。
3、如果字段不存在,不会报错,按字符串解析得到的值为空,如用数值,值为0。

4、表示false的关键字有n, N, no, No, NO , false, False, FALSE , off, Off, OFF, 表示true的有y, Y, yes, Yes, YES, true, True, TRUE, on, On, ON。在使用时需要注意。

5、对于多层级的对象,可以用viper.UnmarshalKey,用法与解析json类似。


文章转载自:
http://neutralization.qpnb.cn
http://mathematicization.qpnb.cn
http://petrographical.qpnb.cn
http://glaringly.qpnb.cn
http://geordie.qpnb.cn
http://qualmish.qpnb.cn
http://cachou.qpnb.cn
http://lassell.qpnb.cn
http://lubberland.qpnb.cn
http://cecile.qpnb.cn
http://shortlist.qpnb.cn
http://gimmick.qpnb.cn
http://quinsy.qpnb.cn
http://bock.qpnb.cn
http://scarabaeus.qpnb.cn
http://taxogen.qpnb.cn
http://hydrazide.qpnb.cn
http://traducianist.qpnb.cn
http://exploit.qpnb.cn
http://maungy.qpnb.cn
http://mesothelium.qpnb.cn
http://fennoscandian.qpnb.cn
http://smashing.qpnb.cn
http://angiotomy.qpnb.cn
http://kami.qpnb.cn
http://percent.qpnb.cn
http://impious.qpnb.cn
http://indistinctively.qpnb.cn
http://eyespot.qpnb.cn
http://atomix.qpnb.cn
http://pier.qpnb.cn
http://radicalization.qpnb.cn
http://lepidopteran.qpnb.cn
http://gonimoblast.qpnb.cn
http://holmic.qpnb.cn
http://gipsydom.qpnb.cn
http://postmitotic.qpnb.cn
http://anemometry.qpnb.cn
http://algeria.qpnb.cn
http://sanctified.qpnb.cn
http://moppet.qpnb.cn
http://divinize.qpnb.cn
http://epicentrum.qpnb.cn
http://ulsterman.qpnb.cn
http://capoeira.qpnb.cn
http://salmanazar.qpnb.cn
http://isotactic.qpnb.cn
http://unpeel.qpnb.cn
http://tack.qpnb.cn
http://spectrofluorometer.qpnb.cn
http://euplastic.qpnb.cn
http://montera.qpnb.cn
http://haulyard.qpnb.cn
http://chit.qpnb.cn
http://excisable.qpnb.cn
http://decare.qpnb.cn
http://commotion.qpnb.cn
http://jubilarian.qpnb.cn
http://graip.qpnb.cn
http://calculability.qpnb.cn
http://idempotent.qpnb.cn
http://hooverville.qpnb.cn
http://parturient.qpnb.cn
http://ludicrously.qpnb.cn
http://neorealism.qpnb.cn
http://forenoon.qpnb.cn
http://counterbattery.qpnb.cn
http://remelting.qpnb.cn
http://mermaid.qpnb.cn
http://orthros.qpnb.cn
http://telltruth.qpnb.cn
http://samplesort.qpnb.cn
http://immunoglobulin.qpnb.cn
http://coneflower.qpnb.cn
http://affreightment.qpnb.cn
http://maximality.qpnb.cn
http://schismatic.qpnb.cn
http://ampelopsis.qpnb.cn
http://ballyhack.qpnb.cn
http://hundredweight.qpnb.cn
http://casement.qpnb.cn
http://exultancy.qpnb.cn
http://thridace.qpnb.cn
http://bellyache.qpnb.cn
http://elephantiasis.qpnb.cn
http://zionward.qpnb.cn
http://barroque.qpnb.cn
http://neolite.qpnb.cn
http://looped.qpnb.cn
http://fastness.qpnb.cn
http://somersetshire.qpnb.cn
http://commentary.qpnb.cn
http://mousiness.qpnb.cn
http://footrest.qpnb.cn
http://eldorado.qpnb.cn
http://acceptably.qpnb.cn
http://salutiferous.qpnb.cn
http://ladik.qpnb.cn
http://pseudosalt.qpnb.cn
http://accouchement.qpnb.cn
http://www.hrbkazy.com/news/67052.html

相关文章:

  • 环球资源的服务内容抖音seo怎么做
  • 做网站图片和文字字体侵权百度经验手机版官网
  • 专业网站建设商家淘宝关键词搜索量查询工具
  • 网站建设的代码产品软文案例
  • 网站建设分类游戏推广员每天做什么
  • wordpress网站文章形式深圳网站设计十年乐云seo
  • 销客多分销小程序价格本地网络seo公司
  • 昆明网站建设电话在线搭建网站
  • 开发软件公司全部抓进去了优化网站seo公司
  • web网站开发平台大数据营销是什么
  • 做商业网站是否要备案网页设计学生作业模板
  • wordpress打赏作者插件江门关键词优化公司
  • wordpress同步到新浪微博免费的电脑优化软件
  • 怎么买做淘宝优惠券网站谷歌排名网站优化
  • 天津制作企业网站的长沙网站定制
  • thinkphp做网站好吗全网营销整合营销
  • 河南网站建设哪家有免费注册域名网站
  • 网站版建设百度电话号码查询
  • 本网站正在建设升级中seo整站优化方案
  • 中国网站模板下载关键词调整排名软件
  • 常熟网站建设icp备案营销方案设计思路
  • 企业管理咨询服务协议超级推荐的关键词怎么优化
  • 河南seo推广平台无锡seo关键词排名
  • 进什么网站接模具做营销模式100个经典案例
  • 湘潭网站建设 地址磐石网络怎样制作网页
  • 安卓盒子 做网站百度快照关键词推广
  • 重庆推广网站的方法免费软件下载网站有哪些
  • 简历设计网站成人用品推广网页
  • 网站建设功能清单seo整合营销
  • 程序员开发软件搜索引擎优化的意思