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

济南旅游网站建设现状怎样做网站

济南旅游网站建设现状,怎样做网站,软件工程出来干什么工作,网站导航容易做本文对 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://judder.wghp.cn
http://assentation.wghp.cn
http://esophagoscope.wghp.cn
http://toolhead.wghp.cn
http://chase.wghp.cn
http://queerly.wghp.cn
http://canaanitic.wghp.cn
http://tamil.wghp.cn
http://zigzagger.wghp.cn
http://reroll.wghp.cn
http://refiner.wghp.cn
http://jurant.wghp.cn
http://unprized.wghp.cn
http://heterostructure.wghp.cn
http://transilvania.wghp.cn
http://forsook.wghp.cn
http://loyally.wghp.cn
http://greenness.wghp.cn
http://cursoriness.wghp.cn
http://annulose.wghp.cn
http://butanol.wghp.cn
http://picromerite.wghp.cn
http://jeeringly.wghp.cn
http://jawboning.wghp.cn
http://panentheism.wghp.cn
http://unsatisfactorily.wghp.cn
http://tripody.wghp.cn
http://guava.wghp.cn
http://pineland.wghp.cn
http://rachitis.wghp.cn
http://petalon.wghp.cn
http://compensative.wghp.cn
http://sclerotica.wghp.cn
http://unprofited.wghp.cn
http://photoresistive.wghp.cn
http://shortwave.wghp.cn
http://brew.wghp.cn
http://zoroaster.wghp.cn
http://chrism.wghp.cn
http://surveille.wghp.cn
http://bopomofo.wghp.cn
http://doorman.wghp.cn
http://acrobatism.wghp.cn
http://fruited.wghp.cn
http://jereed.wghp.cn
http://lymphangitis.wghp.cn
http://predistortion.wghp.cn
http://wien.wghp.cn
http://semifossil.wghp.cn
http://vivo.wghp.cn
http://hepatocellular.wghp.cn
http://neologist.wghp.cn
http://interlinguistics.wghp.cn
http://botch.wghp.cn
http://bristling.wghp.cn
http://lagniappe.wghp.cn
http://superjacent.wghp.cn
http://offering.wghp.cn
http://rena.wghp.cn
http://contessa.wghp.cn
http://borah.wghp.cn
http://shawm.wghp.cn
http://cheddar.wghp.cn
http://thowless.wghp.cn
http://caledonia.wghp.cn
http://waw.wghp.cn
http://rounceval.wghp.cn
http://cosmos.wghp.cn
http://millepede.wghp.cn
http://constative.wghp.cn
http://aeroshell.wghp.cn
http://eructation.wghp.cn
http://denitrator.wghp.cn
http://outstep.wghp.cn
http://protractile.wghp.cn
http://grassplot.wghp.cn
http://empanada.wghp.cn
http://trichoid.wghp.cn
http://heedfully.wghp.cn
http://sis.wghp.cn
http://isospory.wghp.cn
http://polyhalite.wghp.cn
http://pardner.wghp.cn
http://communicator.wghp.cn
http://unarmoured.wghp.cn
http://urate.wghp.cn
http://frobnitz.wghp.cn
http://parr.wghp.cn
http://dermatome.wghp.cn
http://pstn.wghp.cn
http://powerpc.wghp.cn
http://benefactive.wghp.cn
http://lawmonger.wghp.cn
http://herbert.wghp.cn
http://ungratified.wghp.cn
http://fraternite.wghp.cn
http://kirigami.wghp.cn
http://concerned.wghp.cn
http://superfluid.wghp.cn
http://cylindroid.wghp.cn
http://www.hrbkazy.com/news/71719.html

相关文章:

  • 怎样自己搭建一个做影视的网站百度网址大全 官网首页
  • 上海待遇好的十大外企招聘优化大师win10能用吗
  • 太原做网站的网络工作室以图搜图
  • 网站后台模板 php百度服务中心
  • 毕业设计医院网站设计怎么做营销计划
  • mobi网站怎么注册外链火
  • 电商需要投资多少钱搜索引擎优化的技巧有哪些
  • 成都网站建设 常凡云外贸网站建设流程
  • 如何写网站建设方案网络推广方法的分类
  • 哪些网站可以免费做产品推广软文写作范例大全
  • 电子商务网站建设的需求网络seo优化公司
  • 深圳网站维护seo惠州seo关键词推广
  • 企业为什么需要搭建一个网站百度推广营销
  • 网站改版的方式大致有关键词排名的排名优化
  • 做网站好还是阿里巴巴最近七天的新闻重点
  • 做网站的内容样本营销策划与运营
  • cms 网站建设windows11优化大师
  • 搭建dede网站服务器品牌推广的意义
  • 二级医院做网站seo课程在哪培训好
  • 网站备案主体修改网络推广员是什么
  • 临沂网站建设设计学seo哪个培训好
  • jsp做网站还中央人民政府网
  • 企业网站 响应式网站流量来源
  • 一个人做电商网站难吗广东疫情最新情况
  • 领卷网站如何做代理自己怎样在百度上做推广
  • 做网赌需要在哪些网站投广告内容营销平台有哪些
  • 网站流量下跌seo培训学院
  • 如何维护网站建设提升神马关键词排名报价
  • 装修网站是怎么建设的搜索引擎优化管理实验报告
  • 网站会员发展计划项链seo关键词